0

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.

per1234
4,2782 gold badges24 silver badges43 bronze badges
asked Apr 15, 2016 at 3:42
1
  • Keyboard.println((char) KEY_ENTER); might be the problem? Commented Apr 15, 2016 at 7:11

1 Answer 1

4

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);
answered Apr 15, 2016 at 9:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.