Go Down

Topic: Keyboard.Write with Number Pad Keys from Leonardo (Read 11009 times) previous topic - next topic

boxgamex

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.

johnwasser

#1
Jul 27, 2013, 02:33 am Last Edit: Jul 27, 2013, 02:38 am by johnwasser Reason: 1
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
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

boxgamex


pplg

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 :)

electricwah

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

johnwasser

#5
Apr 27, 2020, 07:33 pm Last Edit: Apr 27, 2020, 07:37 pm by johnwasser
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
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

tobedefined

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') ?

pcbbc



Go Up