0

I'm using a ItsyBitsy 32u4, Adafruit says it can act as a USB HID keyboard. The mc is based on the 32u4 which the Keyboard docs say are supported.

I have a simple sketch that prints "A" every second and should press "A". When I upload the sketch and connect to the serial port I see the print output but I don't get any key presses.

Any ideas? I'm on linux, I suspect that the controller doesn't register as a HID device, maybe I need UDEV rules or drivers?

EDIT: the keyboard works on a different computer.

#include <Keyboard.h>
void setup() {
 Serial.begin(9600);
 Keyboard.begin();
 Serial.println("Start");
}
void loop() {
 Serial.println("a");
 Keyboard.write('a');
 delay(1000);
}
asked Jul 5, 2019 at 5:46
7
  • you shoukd read the reference and study the examples Commented Jul 5, 2019 at 6:42
  • @Juraj I have, what do you think I missed? Commented Jul 5, 2019 at 17:42
  • it seemed you missed what is in the Answer. do you have a text editor open in foreground? Commented Jul 5, 2019 at 20:18
  • Yeah, I have a window focused that accepts and displays keyboard input. Typing on my actual keyboard displays the keys. Commented Jul 5, 2019 at 22:32
  • next I would try removing Serial from the sketch Commented Jul 6, 2019 at 5:18

2 Answers 2

2

Keyboard.press() expects a character, but you are passing a character array. Also Keyboard.press() only presses but does not release the key. Keyboard.releaseAll() can be used to release all keys.

I would try:

Keyboard.press('A') ; //note the ' instead of "
Keyboard.releaseAll();

or preferably:

Keyboard.write('A'); //handles press and release of basic keys
answered Jul 5, 2019 at 6:34
2
  • I made an error when I created my simple repo sketch, but I have tried Keyboard.press('A') and Keyboard.write('A'). Neither work. Commented Jul 5, 2019 at 17:31
  • I also tried Keyboard.write('a') after reading keyboard.cpp and realizing that writing 'A' sends keypesses for a and the shift modifier. Commented Jul 5, 2019 at 17:44
0

There was some issue with my laptop, not controller or the sketch.

I tried the my board with another computer and it worked. I tried a commercial keyboard on my first computer it also didn't work.

Both keyboards work after a reboot.

answered Jul 6, 2019 at 6:18

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.