Keyboard.Write with Number Pad Keys from Leonardo

Has anyone ever actually been able to trigger the keypress of a number pad key using the Keyboard.write commands from an Arduino? I can trigger keys like a-z, 0-9 fine, but I either cannot find the appropriate ascii/hex (despite many different results found on google that I have attemtped) or it just doesnt work. I have even tried the hex codes outlined by the USB organization (http://www.usb.org/developers/devclass_docs/Hut1_11.pdf) with no luck.

I think you will need to call keyboard.press(value) and keyboard.release(value) (or .releaseAll()).

The keypad keys are 84 through 99 (0x54 through 0x63) but the keyboard.press() function will treat values below 128 (0x7F) as "printable" so it will look them up in a table of ascii keycodes. To get past that you have to add 136 to the keycode. Try these:

220 '\334' Keypad / 221 '\335' Keypad * 222 '\336' Keypad - 223 '\337' Keypad + 224 '\340' Keypad ENTER 225 '\341' Keypad 1 and End 226 '\342' Keypad 2 and Down Arrow 227 '\343' Keypad 3 and PageDn 228 '\344' Keypad 4 and Left Arrow 229 '\345' Keypad 5 230 '\346' Keypad 6 and Right Arrow 231 '\347' Keypad 7 and Home 232 '\350' Keypad 8 and Up Arrow 233 '\351' Keypad 9 and PageUp 234 '\352' Keypad 0 and Insert 235 '\353' Keypad . and Delete

that worked perfectly. Thanks!

johnwasser: I think you will need to call keyboard.press(value) and keyboard.release(value) (or .releaseAll()).

The keypad keys are 84 through 99 (0x54 through 0x63) but the keyboard.press() function will treat values below 128 (0x7F) as "printable" so it will look them up in a table of ascii keycodes. To get past that you have to add 136 to the keycode. Try these:

220 '\334' Keypad / 221 '\335' Keypad * 222 '\336' Keypad - 223 '\337' Keypad + 224 '\340' Keypad ENTER 225 '\341' Keypad 1 and End 226 '\342' Keypad 2 and Down Arrow 227 '\343' Keypad 3 and PageDn 228 '\344' Keypad 4 and Left Arrow 229 '\345' Keypad 5 230 '\346' Keypad 6 and Right Arrow 231 '\347' Keypad 7 and Home 232 '\350' Keypad 8 and Up Arrow 233 '\351' Keypad 9 and PageUp 234 '\352' Keypad 0 and Insert 235 '\353' Keypad . and Delete

I just want to say THANK YOU, John. You saved me! Thanks for sharing this, really :)

Why 136? what is the significance of this number that makes this work?

electricwah: Why 136? what is the significance of this number that makes this work?

Look at the library source code (libraries/Keyboard/src/Keyboard.c). The first 128 (0-127) values are treated as ASCII and translated to US English keycodes through a lookup table. The next 8 (128-135) are the modifier keys (left and right Shift, Control, Alt, and GUI). Anything above 135 has 136 subtracted from it and then used as a raw USB HID page-7 key code. Because the byte can only hold values up to 256, only key codes up to 120 can be used. This is sufficient for a US English 101-key PC/AT keyboard but not for some keys on some non-English keyboards and various keys on extended keyboards.

See the table starting at Page 53: https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf

johnwasser: 220 '\334' Keypad / 221 '\335' Keypad * 222 '\336' Keypad - 223 '\337' Keypad + 224 '\340' Keypad ENTER 225 '\341' Keypad 1 and End 226 '\342' Keypad 2 and Down Arrow 227 '\343' Keypad 3 and PageDn 228 '\344' Keypad 4 and Left Arrow 229 '\345' Keypad 5 230 '\346' Keypad 6 and Right Arrow 231 '\347' Keypad 7 and Home 232 '\350' Keypad 8 and Up Arrow 233 '\351' Keypad 9 and PageUp 234 '\352' Keypad 0 and Insert 235 '\353' Keypad . and Delete

Thank you. That was just what i was looking for. BTW: What does the second column mean (e. g. '\334') ?

Octal. Base 8.

pcbbc:
Octal. Base 8.

Thx