Yet again I found myself scouring for this information, so, like with version information, here's my handy little table of info. All numbers are in decimal, and I'm pretty sure they're correct (tested the majority of them out). N/A means you can't get to that code without using a modifier (or the code doesn't exist at all). Some codes are dupes (such as the letters of the alphabet are dupes in the AsyncKeyDown category).
| AscB( Key ) | Keyboard.AsyncKeyDown | Explanation | |
| 0 | N/A | Null Byte | |
| 1 | 115 | Home | |
| 4 | 119 | End | |
| 5 | 114 | Insert | |
| 8 | 51 | Backspace | |
| 9 | 48 | Tab | |
| 11 | 116 | Page Up | |
| 12 | 121 | Page Down | |
| 13 | 36 | Return | |
| 27 | 53 | Escape | |
| 28 | 123 | Left Arrow | |
| 29 | 124 | Right Arrow | |
| 30 | 125 | Down Arrow | |
| 31 | 126 | Up Arrow | |
| 32 | 49 | Space | |
| 33 | N/A | ! | |
| 34 | N/A | " | |
| 35 | N/A | # | |
| 36 | N/A | $ | |
| 37 | N/A | % | |
| 38 | N/A | & | |
| 39 | 39 | ' | |
| 40 | N/A | ( | |
| 41 | N/A | ) | |
| 42 | N/A | * | |
| 43 | N/A | + | |
| 44 | 43 | , | |
| 45 | 27 | - | |
| 46 | 47 | . | |
| 47 | 44 | / | |
| 48 | 29 | 0 | |
| 49 | 18 | 1 | |
| 50 | 19 | 2 | |
| 51 | 20 | 3 | |
| 52 | 21 | 4 | |
| 53 | 23 | 5 | |
| 54 | 22 | 6 | |
| 55 | 26 | 7 | |
| 56 | 28 | 8 | |
| 57 | 25 | 9 | |
| 58 | N/A | : | |
| 59 | 41 | ; | |
| 60 | N/A | < | |
| 61 | N/A | = | |
| 62 | N/A | > | |
| 63 | N/A | ? | |
| 64 | N/A | @ | |
| 65 | 0 | A | |
| 66 | 11 | B | |
| 67 | 8 | C | |
| 68 | 2 | D | |
| 69 | 14 | E | |
| 70 | 3 | F | |
| 71 | 5 | G | |
| 72 | 4 | H | |
| 73 | 34 | I | |
| 74 | 38 | J | |
| 75 | 40 | K | |
| 76 | 37 | L | |
| 77 | 46 | M | |
| 78 | 45 | N | |
| 79 | 31 | O | |
| 80 | 35 | P | |
| 81 | 12 | Q | |
| 82 | 15 | R | |
| 83 | 1 | S | |
| 84 | 17 | T | |
| 85 | 32 | U | |
| 86 | 9 | V | |
| 87 | 13 | W | |
| 88 | 7 | X | |
| 89 | 16 | Y | |
| 90 | 6 | Z | |
| 91 | 33 | [ | |
| 92 | 42 | \ | |
| 93 | 30 | ] | |
| 94 | N/A | ^ | |
| 95 | N/A | _ | |
| 96 | 50 | ` | |
| 97 | 0 | a | |
| 98 | 11 | b | |
| 99 | 8 | c | |
| 100 | 2 | d | |
| 101 | 14 | e | |
| 102 | 3 | f | |
| 103 | 5 | g | |
| 104 | 4 | h | |
| 105 | 34 | i | |
| 106 | 38 | j | |
| 107 | 40 | k | |
| 108 | 37 | l | |
| 109 | 46 | m | |
| 110 | 45 | n | |
| 111 | 31 | o | |
| 112 | 35 | p | |
| 113 | 12 | q | |
| 114 | 15 | r | |
| 115 | 1 | s | |
| 116 | 17 | t | |
| 117 | 32 | u | |
| 118 | 9 | v | |
| 119 | 13 | w | |
| 120 | 7 | x | |
| 121 | 16 | y | |
| 122 | 6 | z | |
| 123 | N/A | { | |
| 124 | N/A | | | |
| 125 | N/A | } | |
| 126 | N/A | ~ | |
| 127 | 117 | Delete | |
| 200 | 122 | F1 | |
| 201 | 120 | F2 | |
| 202 | 99 | F3 | |
| 203 | 118 | F4 | |
| 204 | 96 | F5 | |
| 205 | 97 | F6 | |
| 206 | 98 | F7 | |
| 207 | 100 | F8 | |
| 208 | 101 | F9 | |
| 209 | 109 | F10 | |
| 210 | 103 | F11 | |
| 211 | 111 | F12 | |
| N/A | 105 | Print Screen | |
| N/A | 107 | Scroll Lock | |
| N/A | N/A | Pause |
Sorry for running off, I decided to drown my troubles in a Rolling Stones Concert in Puerto Rico last night, just got back, whats going on?
Very cool. Maybe you should put this on a separate page.
And don't forget that some of the AsyncKeyDown codes are only valid on U.S. keyboards! (Aaron, you should know that and not post such a table without this disclaimer)
What would really be helpful is to post code for inquiring the actual key codes from given Asc codes and vice versa, so that a program can be made international-savvy. Or, even better, that RB provides internal functions for that, x-platform.
Actually Thomas, I wasn't aware of that. I'm so used to using the Win32 virtual keys (since that's all I usually work with) that it didn't even dawn on me that the key codes were keyboard-specific. Thanks for pointing that out!
OK, here's a few hints:
1.
The non-letter keys have the same position and codes on all keyboards. That includes the F-Keys, modifiers, cursor block, Return, Enter, Tab, Backspace, Space.
2.
All but the U.S. keyboards have one more key between the Shift and the Z key. Japanese kbds have even more keys (only around the space bar, IIRC).
3.
Any of the letter keys can have different character codes, including the digit keys! Although I AFAIR, the number block on the large kbds is not changing (although, the Mac kbds have an extra key there over Windows kbds)
4.
Even japanese kbds have roman letters on them, so if you tell a japanese user to press "a", he'll find that key. Just don't assume it's the one on the left.
5.
In general, the scan codes usually do not change their position. the key with scan code 0 is always the leftmost one in the mittle alpha row (giving "a" on US kbds). But be aware that some of the modifier keys can actually move around, so do not assume that the bottom leftmost key always gives you the code of the control key, in case you try to describe the keys in a picture to the user) On the Mac, for instance, the user can now choose to swap the modifier keys around (because some old unix geeks are rather having the control key where we have the caps lock key).
6.
French kbds are especially particular: Their original typewriters had the digit keys swapped with what we usually get when using Shift! That means: Typing the key with the number "1" on it would give a symbol and only by using Shift you'd get the digit. Nowadays french users have the choice to use this old layout or the common one we all use where you'd get the digits without shifting.
7.
Some keys may be compound keys on non-US kbds. E.g, the leftmost key in the digit row on german kbds gives ^ - but after pressing that key, the system waits for a followup key: if you press the space bar, you'll get the ^, if you press a, you'll get â. This waiting for another key can cause some trouble if you scan codes in a text editor field. Even the 2006 IDE on Mac OS causes to screws this up still (I then start getting wrong characters all the time until I quit the IDE).
8.
Some keys may need to require the Alt and the Ctrl ke pressed. E.g, this is the case for these keys on a german kbd: \ { } [ ] | @
So, be careful if you let the user type a key and then also check separately for the press of Ctrl or Alt! If you, for instance, want to differentiate between Ctrl-\ and \, you'll not get it working on a German kbd, because the Ctrl key will ALWAYS be down to get this key.
Hmm, someone should really add all this to the rbwiki.org site
BTW, is AsyncKeyDown the only way to get the scan code of a pressed key? That wouldn't be good because when the app gets to check for the key, the user may have already let go of it again, and then you won't get your scan code. Instead, there should be a non-Async version of KeyDown, just like there are those for the modifier keys.
Oh, and I just found that there is a Keyboard.KeyName function. That comes close to what we need, but not completely: It gives you only the unshiftet char code for a scan code, which is not enough to be international-savvy. Plus, it's giving english names (when I tell a German user to press the Control key, most of them do not know what I mean, they are so used to using only the german term instead)
As a resume of the above:
If you want to use command shortcuts (via Command or Control) into your menus, use ONLY plain alpha shortcuts!
As soon as you start with commands such as Ctrl-[ you will cause trouble for the non-English kbd users. And, BTW, the RB IDE gives a bad example here, and I as a german user can tell you that I can't type many of those shortcuts ever! (and it's worse on Windows that on the Mac) And RB does not provide a way to even localize those from the outside as one can usually do with standard Mac apps (through their resource data) because RB-built apps have those shortcuts hammered fixed into the code. Makes localization quite impossible if you do not have access to the source code.
Oh, here's another one for the record: Newer Mac kbds have 16 F-Keys, while older ones have 15. On the PC side, 12 F-Keys are official, the next 3 on the row being called Print Screen, Scroll Lock and Pause (on the Mac, they are F13-F15 and sometimes do not come thru to the app, just like Pause doesn't on the PC).
It's best not to rely on pressing any of these keys on a Mac, as they're often used for global functions, not for app-specific ones.