MMBasic generates a single unique character for the function keys and other special keys on the keyboard.
These are shown in the table as hexadecimal and decimal numbers:
Keyboard Key | Key Code (Hex) | Key Code (Decimal) |
Up Arrow | 80 | 128 |
Down Arrow | 81 | 129 |
Left Arrow | 82 | 130 |
Right Arrow | 83 | 131 |
Insert | 84 | 132 |
Home | 86 | 134 |
End | 87 | 135 |
Page Up | 88 | 136 |
Page Down | 89 | 137 |
Alt | 8B | 139 |
Num Lock | 8C | 140 |
F1 | 91 | 145 |
F2 | 92 | 146 |
F3 | 93 | 147 |
F4 | 94 | 148 |
F5 | 95 | 149 |
F6 | 96 | 150 |
F7 | 97 | 151 |
F8 | 98 | 152 |
F9 | 99 | 153 |
F10 | 9A | 154 |
F11 | 9B | 155 |
F12 | 9C | 156 |
If the control key is simultaneously pressed then 20 (hex) is added to the code (this is the equivalent of setting bit 5). If the shift key is simultaneously pressed then 40 (hex) is added to the code (this is the equivalent of setting bit 6). If both are pressed 60 (hex) is added. For example Control-PageDown will generate A9 (hex).
The shift modifier only works with the function keys F1 to F12; it is ignored for the other keys.
MMBasic will translate most VT100 escape codes generated by terminal emulators such as Tera Term and Putty to these codes (excluding the shift and control modifiers). This means that a terminal emulator operating over a USB or a serial port opened as console will generate the same key codes as a directly attached keyboard. This is particularly useful when using the EDIT command.
KEYDOWN FUNCTION
The KEYDOWN function makes it easy to tell if the user is holding down a key like an arrow key.
Leave a Reply