Share via

Question about KEYBDINPUT structure

Xiaodong Hu 21 Reputation points
2020-09-09T09:48:27.373+00:00

I'm reading this article: https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-keybdinput

In the Remarks part, it says that "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."
However, as far as I know. The scan code may be different for different keyboards but the keyboard's driver will translate the scan code to virtual key value for the OS to handle the input.
So should it be the scan code of a key may alter depending on the current keyboard, but the virtual code will always be the same?

Please correct me if I'm wrong. Thanks!

Windows development | Windows API - Win32
0 comments No comments

Answer accepted by question author

Rita Han - MSFT 2,171 Reputation points
2020-09-09T10:21:09.733+00:00

Hello @Xiaodong Hu ,

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.

This is based on the the fact that OS is Windows and hardware is not changed.

Since the scan code is from hardware so if the hardware keeps unchanged and scan code will be the same.

Since the keyboard layout can be changed via Settings. There is a such case, virtual code [VK_OEM_4 (0xDB) in the US standard keyboard is correspond the '{' key but maybe another different key in another different keyboard layout.

Thank you!


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.