February 12th, 2026
0 reactions

How can I distinguish between the numeric keypad 0 and the top-row 0 in the WM_KEY­DOWN message?

A customer wanted to know how to distinguish between the numeric keypad 0 and the top-row 0 in the WM_KEY­DOWN 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_KEY­DOWN 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_NUMPAD0, it seems pretty clear that we have the numeric keypad 0. But when it is VK_INSERT, 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_CHAR 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.)

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments