Question about KEYBDINPUT structure

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

I'm reading this article: https://video2.skills-academy.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 API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,498 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rita Han - MSFT 2,161 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.


0 additional answers

Sort by: Most helpful