I have a Teensy set up as a keyboard, joystick, and I'm giving keyboard commands. Letter and number keys are going fine. But when I try sending ENTER, I get some extra code in my Linux terminal:
$ 16424
16424: command not found
the code I have to give the ENTER key goes like this:
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// read the digital inputs and set the buttons
Joystick.button(1, digitalRead(0));
Serial.println(digitalRead(0));
if(digitalRead(0)==0){
Keyboard.println(KEY_ENTER);
}
delay(50);
}
where is this "16424" coming from, and how do I send an ENTER keypress? I am using a Teensy 2.0, on Linux, with Arduino IDE 1.6.7.
-
Keyboard.println((char) KEY_ENTER); might be the problem?Mikael Patel– Mikael Patel2016年04月15日 07:11:57 +00:00Commented Apr 15, 2016 at 7:11
1 Answer 1
You can't just "print" a key like that. You use print
for sending text.
When you use println
it sends an enter key along with your text, so you can do :
Keyboard.println("ls -al");
and it will send the text ls -al
and press enter for you.
If you want to do it in the 'raw' way you will need to press and then release the key:
Keyboard.press(KEY_ENTER);
Keyboard.release(KEY_ENTER);