Why do winapi functions need scan code although there is a keyboard driver?

282 views Asked by At

In msdn,

typedef struct tagKEYBDINPUT {
  WORD      wVk;
  WORD      wScan;
  DWORD     dwFlags;
  DWORD     time;
  ULONG_PTR dwExtraInfo;
} KEYBDINPUT, *PKEYBDINPUT, *LPKEYBDINPUT;

wVk
Type: WORD
A virtual-key code. The code must be a value in the range 1 to 254. If the dwFlags member specifies KEYEVENTF_UNICODE, wVk must be 0.

Keyboard drivers do convert virtual key codes to scan codes. But why do winapi functions require scan codes? Is it because the API directly tells OS and doesn't rely on keyboard drivers?

1

There are 1 answers

0
YangXiaoPo-MSFT On BEST ANSWER

One benefit has been explained in the following Remarks.

Set the KEYEVENTF_SCANCODE flag to define keyboard input in terms of the scan code. This is useful to simulate a physical keystroke regardless of which keyboard is currently being used. The virtual key value of a key may alter depending on the current keyboard layout or what other keys were pressed, but the scan code will always be the same.