Key Mapper Developer Blog

Remapping Pause and Num Lock

The Num Lock key (along with the Insert key) is one of the keys most likely to be disabled by any scancode mapping program: it is hardly ever used and the effects of accidental pressing it are confusing and annoying, to users and support teams. There are 133 637 results when searching the Microsoft support site for Num Lock. Keyboard design is staunchly conservative, though, and the 101/102 keyboard keys have remained essentially unchanged since introduced by IBM in 1984.

 

One of the reasons for the conservatism is that keyboards use numeric codes - scancodes - to identify which physical key has been pressed. These scancodes include one bit to identify the key itself, and an extra bit to show if the key is extended. This derives from the extension of the original 83/84 PC/AT keyboard to the 101 key keyboard: in some cases where the functionality was the same, rather than assign a whole scancode to the extra keys, an extra bit was added. For example the Enter and Return keys both have a scancode of 28 (0x1C), while the Enter key (the one on the numeric keypad) has the extended bit set; similarly the Left arrow key and the number 4 on the numeric keypad (which is Left with Num Lock set off) both have a scancode of 75 (0x4B), but the arrow key has the extended bit set. This was presumably for backward compatibility with systems which didn't expect the extra extended bit.

 

Keyboard drivers can change or interpret these codes themselves - and often do: although keyboard power and standby keys have been assigned specific scancodes, the actual operations are controlled by the keyboard driver; this means that a) the power keys usually can't be disabled using scancode mapping and b) it isn't possible to assign an existing key to these functions. Scancode mapping programs like KeyMapper usually allow the selection of the key to be disabled by reading the keypress: Num Lock, unlike all other keys, reports itself differently on different keyboards. Most keyboards use the usual code - 69 (0x45) - to identify the key with the extended bit set off, but some set the extended bit on. This can cause confusion, as systems expect the code of 69 with extended on to represent the Euro symbol, on keyboards which have that. Using that key code in a scancode mapping also fails to correctly map Num Lock: scancode of 69 without the extended bit set must be used in mappings no matter what the keyboard reports as the scancode.

 

The Num Lock key is also involved in the most complicated remapping scenario, the Pause key. At first I couldn't figure out how to remap the Pause key at all, and thought that it couldn't be done. Then I stumbled across a blog post which indicated it was possible and provided me with enough information to work out how to implement it.

 

When the Pause key is pressed, internally this generates multiple keystrokes, specifically Ctrl and Num Lock. This is explained by another blog post, coincidentally posted within two days of the other one.

in the original PC/XT keyboard layout, there was no Break key. The key sequence for Break was Ctrl+ScrollLock. (And for completeness, the key sequence for Pause was Ctrl+NumLock.) Even though the enhanced keyboard moved the Pause and Break functions to their own key, pressing the Pause key internally generated scan codes that simulated a press of Ctrl+NumLock. In other words, when you pressed Pause, the keyboard hardware actually tells the computer, "The user pressed the Ctrl key and then pressed the NumLock key."

 

That's not quite the whole story, though - so systems can distinguish this from a regular Ctrl-NumLock, a different extended value is used - instead of 224 (0xe0) the keyboard will report 225 (0xE1). This is as far as I know the only time this extra extended value is used.

 

This complicated the UI for KeyMapper: should a user want to disable or remap the Pause key, then Num Lock will still fire each time it's pressed: to remap Pause to a single keystroke, Num Lock must be disabled as otherwise Num Lock will be toggled each time Pause is pressed.

 

However, it also introduced an interesting new possibility: if Num Lock is remapped to another key then that key will also be 'pressed' when the remapped Pause is pressed: this means the Pause key can be remapped to a keyboard command which requires two key strokes, for example Windows-L (the shortcut to Lock Computer), or Right-Alt and 4 for the Euro symbol. These require the Pause key to be remapped to the first key in the sequence and Num Lock to be remapped to the second.

If you want to leave a comment, all fields are optional except the text.
Comments are moderated, so won't show up immediately.