A customer wanted to know how to distinguish between the numeric keypad 0 and the top-row 0 in the WM_ message. And while we’re at it, let’s also distinguish between the numeric keypad 0 and the Ins key.
We start with this table of what you get in the WM_ message when you press the numeric keypad 0.
| Event | wParam |
|---|---|
| Numpad0 with NumLock on | VK_NUMPAD0 |
| Numpad0 with NumLock off | VK_INSERT |
Okay, so when the wParam is VK_, it seems pretty clear that we have the numeric keypad 0. But when it is VK_, we aren’t sure whether it’s the numeric keypad 0 with NumLock off, or whether it’s the dedicated Ins key.
For that, we can look at the lParam, specifically, bit 24, which is documented as the “extended key” bit.
Rewind the clock to 1983. The IBM PC XT keyboard is introduced. To the left of the main keyboard is a set of numbered function keys, and to the right is a numeric keypad. But the keys on the numeric keypad do double-duty because arrows and other editing keys are overlaid onto them.
| ⏎ |
7
Home
|
8
↑
|
9
PgUp
|
|
4
←
|
5
|
6
→
|
|
|
PrtSc
*
|
1
End
|
2
↓
|
3
PgDn
|
|
0
Ins
|
.
Del
|
||
You select whether you want numbers or arrows/editing keys by toggling NumLock.
The IBM PS/2 keyboard expanded the set of keys on the keyboard by inserting a block of keys between the main keyboard and the numeric keypad. This block contains the arrow keys and the editing keys. This keyboard layout closely resembles the keyboard layout used by most keyboards today, so I guess it held up okay.
For compatibility, the bonus keys on the keyboard reported themselves to be the same as the numeric keypad keys they shadowed, but with an extra flag byte to say that they are “extended” keys. They’re “extended” because they weren’t in the original keyboard.
This “extended” terminology has carried forward ever since. So we can distinguish between the dedicated Ins key and a numeric keypad 0 with NumLock off by seeing if we got an extended key. If so, then it came from the editing keys; if not, then it came from the numeric keypad.
| Event | wParam | Extended? |
|---|---|---|
| Numpad0 with NumLock on | VK_NUMPAD0 | 0 |
| Numpad0 with NumLock off | VK_INSERT | 0 |
| Ins key | VK_INSERT | 1 |
Next time, we’ll look at distinguishing the numeric keypad 0 from the top-row 0 in the WM_ message. It’s a little messier.
Bonus chatter: That PrtSc key was a major source of frustration because it sat right next to the shift key. If your finger was slightly misaligned and hit both the shift key and the PrtSc key, you accidentally asked for the screen contents to be sent to the printer. Your computer just hung until you turned on your printer so you could get a printout that you didn’t want. (And if you didn’t have a printer, you were just dead.)
0 comments
Be the first to start the discussion.