Which Keyboard.press code should I use?

Status
Not open for further replies.

rfresh737

Well-known member
I've been searching on the forum for Keyboard.press problems and have a question about which style I should be using for a Teensy 3.6.

This style:

Code:
  Keyboard.begin();
  Keyboard.press(KEY_F1);
  delay(250);
  Keyboard.releaseAll();

or this style:

Code:
Keyboard.set_key1(KEY_F1);
Keyboard.send_now();
delay(250);
Keyboard.set_key1(0);
Keyboard.send_now();


I have a windows app running and my small test sketch doesn't seem to be sending the F1 key press to that app. In the windows app, I should see a button being pressed down when the F1 key press is sent. I can manually press F1 on my keyboard and see the button depress, but when I run the sketch, the button depress does not happen in the app.

Thank you.

Code:
#include <Keyboard.h>       

void setup()
{
  Keyboard.begin();
  Keyboard.press(KEY_F1);
  delay(250);
  Keyboard.releaseAll();     
}

void loop()
{

}
 
Remove '#include <Keyboard.h>' and try again.

Also no need for 'Keyboard.begin()';

That's all Arduino stuff not needed for Teensy.

And finally: you obviously need to set USB type to something that contains the Keyboard interface when compiling.
 
Status
Not open for further replies.
Back
Top