read incomming key wihtout hitting the return-key

Hi Group,
It looks that the only way to get a single key decoded is hitting the return kley.
Is there a way to get a single key, for example the home oresc key, so I can act on it??

Harry

gharryh:
Hi Group,
It looks that the only way to get a single key decoded is hitting the return kley.
Is there a way to get a single key, for example the home oresc key, so I can act on it??

Harry

Perhaps you left out some pretty important information????
Paul

Consider dropping using the serial monitor

Yes, drop the serial monitor, where you pay for the ability to edit your keystrokes before "sending them along" with the button or carriage return.

--> And pick one of any number of serial-port terminal applications google might turn up.

I use CoolTerm, simple, free and easy to use. When I care about seeing each keystroke IRT.

a7

OK maybe some explanation can help.

I want move some servo's using the up/down and left/right keys from my laptop
And hitting the home-key would move both servo's to the 0 pos.
Harry

Use a proper terminal emulator.

Putty, TeraTerm ...

Yes use TeraTerm or CoolTerm and then use this code on the Arduino side

// readOneChar.ino
// Reads one char cmds from Serial
// https://www.forward.com.au/pfod/ArduinoProgramming/SoftwareSolutions/index.html
// Pros: Extremely Simple, Non-blocking and Robust
// Cons: Nothing really. You can do a lot with one char cmds (A..Z,a..z,0..9) plus symbols

void setup() {
  Serial.begin(9600);
  for (int i = 10; i > 0; i--) {
    Serial.print(' '); Serial.print(i);
    delay(500);
  }
  Serial.println();
}

void loop() {
  char c = Serial.read(); // note read() returns an int, char c = converts it to a char
  if (c != -1) {  // read() return -1 if there is nothing to be read.
    // got a char handle it
    Serial.println(c);
  }
}

drmpf:
Yes use TeraTerm or CoolTerm and then use this code on the Arduino side

Thanx but this code depends still on a return after a single character

gharryh:
Thanx but this code depends still on a return after a single character

Not if you use a terminal emulator.

gharryh:
Thanx but this code depends still on a return after a single character

Nope. It is a serial port. It doesn't care.

Both TeraTerm and CoolTerm, by default, send the keypress as soon as you press it.
This results in a lot of very small msgs (one char at a time) so they both have options to 'delay' sending chars to allow them to 'collect' a few to send at once. BUT by default these delays are set to 0 or not enabled so EACH keypress is sent as soon as you hit the key.

Note: On the Arduino receive side you have to use Serial.read() and look at each key. All the other Serial.readxxx methods will sit and wait for 1sec to see if any more chars arrive before allowing the rest of the code to continue.

Serial.readStringUntil('\n') and Serial.readBytesUntil(... , '\n') return when they see the newline so if you use those in your Arduino code, it looks like you need to hit Enter to get the message through, but that is your Arduino code getting in the way.

See my tutorial Arduino Serial I/O for the Real World for more details about using real time Serial.
But for your case the above simple Arduino code and TeraTerm or CoolTerm is all you need

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.