Converting between scancodes and keycodes
Cameron Cawley (3514) 158 posts |
I’m currently using OS_Byte 121 to poll the keyboard. From what I can tell, it returns scancodes that have the same value regardless of the configured keyboard layout, for example the scancode 65 would always be the key next to the Caps Lock key. However, I would also like to convert this to a keycode, where 65 would map to “A” on QWERTY keyboards, and “Q” on AZERTY keyboards. Is there a RISC OS equivalent of the MapVirtualKeyA function on Windows that can be used to convert the scancode to the corresponding keycode? |
Rick Murray (539) 13850 posts |
The RISC OS keyboard handling is a maze of twisty passages, all alike… |
Rick Murray (539) 13850 posts |
FFS. OS_InstallKeyHandler can be used to read the address of the current key handler. The PRM says, and I quote, with my emphasis:
Useful. I ask, because I find myself with a need to know what ASCII character a keypress generates. |
Rick Murray (539) 13850 posts |
I give up. A keyboard handler is supposed to look like this: The handler starts with the following structure: +0: Offset to simple translation table +4: Number of entries in simple translation table +8: Offset to internal key mapping (-ve INKEY) table +12: Offset to list of shifting keys +16: Offset to list of special keys +20: Offset to list of special key code entries +24: Offset to initialisation entry point +28: Offset to pending Alt code routine +32: Optional flags word (present if bit 31 of +4 is set) So… >SYS "OS_InstallKeyHandler", 0 TO address% >PRINT ~address% 200D514 >PRINT ~address%!0 DC263314 > So I have the keyboard handler address, but what is there is… huh? That word is I think I’ll just hardcode a lookup for QWERTY and too bad for everything else. It shouldn’t need to be this hard to get a character code for a regular key press. :-/ |
Julie Stamp (8365) 474 posts |
They’re offsets alright Rick, when I add address% + adress%!0 and adress% + address%!8 I get addresses inside InternationalKeyboard. No idea how to interpret the tables though, I get confused by keyboards and characters. |
Rick Murray (539) 13850 posts |
I’ll have to look again. However, the lookup table has been done (and it was easy enough). Clearly only really useful for a UK layout keyboard, but, then, it’s exactly the same method that Hopper uses. |