Last week, I was working on a project to roll out a number of MS Surfaces as kiosk devices. As part of the configuration, I was required to somehow stop users exiting the kiosk software by pressing Alt-F4 or Esc. After some research (googling), I decided the best way to achieve this was using “scancode maps”.
Keyboards generate scan codes every time you press and release a key. Then those scan codes are converted into a format which can be used by the operating system. As this is the case, you can map the functionality of any of the keys on a keyboard, or other input devices using these scan code maps.
Having understood this, I found several posts online that showed how to disable several keys. It seems you can do this by creating a Registry Item as follows:
Key - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout
Value Name - Scancode Map
Value Type - REG_BINARY
Value Data - 00000000000000000200000000003A0000000000
This particular example disables the Caps Lock key.
However, I couldn’t seem to find a post that gave me the exact string of numbers to achieve what I required. I did however find a table that mapped scan codes to keys here, I just didn’t know how to use them. So I dove into figuring out exactly how to construct the numbers required.
After research, this is how I understand it. The first 16 zeros, are header information and should always be set to zeros. After that, you specify how many keys you are changing, plus one for the null terminating mapping. Following that, you specify the output scan code you want and then the key you want to change. You can specify as many keys as you like, then append the number of mappings. Then finally, it is all followed by a null terminator.
This how it looks if you split the above example up:
00 00 00 00 - Header Version
00 00 00 00 - Header Flags
02 00 00 00 - Number of map entries
00 00 3A 00 - On the right, caps lock and on the left no output (disable)
00 00 00 00 - This is a null terminator
Using this information and the table I found earlier, I was able to determine the final data I needed was as follows:
00 00 00 00
00 00 00 00
03 00 00 00
00 00 01 00
00 00 38 00
00 00 38 E0
00 00 00 00
Once I put that all into one line again and entered it into the registry item I mentioned earlier, this successfully disables the two Alt keys and the Esc key.
All I need to do now is find a subtle way to use this knowledge to prank a colleague 🙂