I made these notes while investigating Teensy keyboard support, then thought they would be useful to share. There are specific bug reports and suggestions for enhancement, in bold.
The key constants are derived from labelling of the US ANSI no-altgr keyboard layout
http://en.wikipedia.org/wiki/File:KB_United_States-NoAltGr.svg
The modifiers (four on Teensyduino, eight in C) are combined with the base keys.
So to send ctrl-C you do
if you are using C and makefiles. Apparently though Teensyduino users don't have things so simple. They need instead to do
Three comments, firstly why do Teensyduino users need to use so many more lines of code? It would be better to add the same function as in the C binding, for the cases where only a single key plus a modifier is pressed, then released.
Secondly, why is there only access to left-hand modifiers? It would be better to support the right-hand modifier keys in Teensyduino as well as the left hand ones.
And thirdly (minor), why the MOFIFIER_KEY_foo vs MODIFIERKEY_foo difference? It would be better to be consistent (although a reason to not be consistent would be that a change might break existing code).
As required by the USB HID Keyboard spec, the key names however refer to layout, not labelling. So for example, to produce ctrl-A on a French AZERTY keyboard
http://en.wikipedia.org/wiki/File:KB_France.svg
requires
because KEY_Q means the leftmost top row key, which is labelled A. This is confusing, and is probably the reason for the A-grave becoming Q-grave bug I reported earlier. But this layout-based naming comes from the USB keyboard spec.
Or, on Teensyduino,
There is no direct support for dead keys, but again by reference to the ANSI keyboard layout they can be produced. So to output ë which, on a French AZERTY keyboard, is typed with the diaresis dead key followed by e, one would do
or on Teensyduino
alt-gr is the same as MODIFIER_KEY_RIGHT_ALT which is available in C but not in Teensyduino. So any keypress that needs alt-gr (€¦ on UK English; €#{[¦`\^@]}¤ on French AZERTY) can only be produced with Keyboard.print();. It would be better to allow the right-hand modifier keys in Teensyduino.
Keys not on the US ANSI layout can't be produced at all by the current Teensy implementation. The menu key, the Fn key, and (on Japanese keyboards) the three keys near the spacebar which control character input methods, and the underscore/backslash keypresses cannot be produced
http://en.wikipedia.org/wiki/File:KB_Japanese.svg
Keyboard Menu has HID code 118 (0x76) so could be supported.
The key constants are derived from labelling of the US ANSI no-altgr keyboard layout
http://en.wikipedia.org/wiki/File:KB_United_States-NoAltGr.svg
The modifiers (four on Teensyduino, eight in C) are combined with the base keys.
So to send ctrl-C you do
Code:
usb_keyboard_press(KEY_C, MODIFIER_KEY_CTRL);
Code:
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.set_key1(KEY_C);
Keyboard.set_key2(0);
Keyboard.set_key3(0);
Keyboard.set_key4(0);
Keyboard.set_key5(0);
Keyboard.set_key6(0);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
Three comments, firstly why do Teensyduino users need to use so many more lines of code? It would be better to add the same function as in the C binding, for the cases where only a single key plus a modifier is pressed, then released.
Secondly, why is there only access to left-hand modifiers? It would be better to support the right-hand modifier keys in Teensyduino as well as the left hand ones.
And thirdly (minor), why the MOFIFIER_KEY_foo vs MODIFIERKEY_foo difference? It would be better to be consistent (although a reason to not be consistent would be that a change might break existing code).
As required by the USB HID Keyboard spec, the key names however refer to layout, not labelling. So for example, to produce ctrl-A on a French AZERTY keyboard
http://en.wikipedia.org/wiki/File:KB_France.svg
requires
Code:
usb_keyboard_press(KEY_Q, MODIFIER_KEY_CTRL);
Or, on Teensyduino,
Code:
Keyboard.set_modifier(MODIFIERKEY_CTRL);
Keyboard.set_key1(KEY_Q);
Keyboard.set_key2(0);
Keyboard.set_key3(0);
Keyboard.set_key4(0);
Keyboard.set_key5(0);
Keyboard.set_key6(0);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
Code:
usb_keyboard_press(KEY_LEFT_BRACE, MODIFIER_KEY_SHIFT);
usb_keyboard_press(KEY_E, 0);
Code:
Keyboard.set_modifier(MODIFIERKEY_SHIFT);
Keyboard.set_key1(KEY_LEFT_BRACE);
Keyboard.set_key2(0);
Keyboard.set_key3(0);
Keyboard.set_key4(0);
Keyboard.set_key5(0);
Keyboard.set_key6(0);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(KEY_E);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
alt-gr is the same as MODIFIER_KEY_RIGHT_ALT which is available in C but not in Teensyduino. So any keypress that needs alt-gr (€¦ on UK English; €#{[¦`\^@]}¤ on French AZERTY) can only be produced with Keyboard.print();. It would be better to allow the right-hand modifier keys in Teensyduino.
Keys not on the US ANSI layout can't be produced at all by the current Teensy implementation. The menu key, the Fn key, and (on Japanese keyboards) the three keys near the spacebar which control character input methods, and the underscore/backslash keypresses cannot be produced
http://en.wikipedia.org/wiki/File:KB_Japanese.svg
Keyboard Menu has HID code 118 (0x76) so could be supported.
Last edited: