Both answers here are wrong.
I don't understand why people vote for wrong answers ??
Both answers suggest that the flag is irrelevant. This is completely wrong. And the flag has NOTHING to do with the keypad.
The correct answer is that there are only scan codes from 01 to 7F but Virtual keys range from 01 to FF.
So as keyboards grew it became necessary that some scan codes have double assignment. For example on my keyboard the scan code 0x45 is assigned to the NumLock key AND to the Pause key.
To distinguish them the keyborard sends the Extended Key flag for the NumLock key but not for the Pause key.
There are several other keys that have double assignment like for example all media keys.
Run Spy++ that comes with the Visual Studio Tools and filter only WM_KEYDOWN and enable "Decoded message parameters" then hit some keys in a text editor.
Spy++ will show you for which keys the flag is set and for which keys it is not set.
Here the output from Spy++:
P WM_KEYDOWN nVirtKey:VK_NUMLOCK cRepeat:1 ScanCode:45 fExtended:1 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYDOWN nVirtKey:VK_PAUSE cRepeat:1 ScanCode:45 fExtended:0 fAltDown:0 fRepeat:0 fUp:0
Another example is the scan code 2E which is assigned to the letter "C" and to VK_VOLUME_DOWN on my keyboard.
You must program it exactly the same way, otherwise keyboard injection with keybd_event()
will fail because another key is hit than the one you intended.
Do NOT trust in MapVirtualKeyEx(MAPVK_VK_TO_VSC_EX)
(>= Vista) because it does not return the extended flag for some keys although they are extended keys, like VK_LEFT for example. Another bug in this function is that it returns the extended flag (E1) for the VK_PAUSE key although this key is not extended.