microsoft / microsoft/terminal

VkKeyScanW(0) is a constant during runtime independent of keyboard layout changes

Open
#8,871 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Input Area-TerminalControl Issue-Bug Priority-2 Product-Terminal
Dominant language
C++
Stars
105k
Forks
9.6k
Avg merge
3d 17h
Merged PRs (30d)
29

Description

Environment

Windows build number: 10.0.19042.0

Steps to reproduce

  1. Add the "US" keyboard layout within the "English (United States)" language
  2. Add the "United Kingdom Extended" layout within the "English (United Kingdom)" language
  3. Run the following code:
    #define NOMINMAX
    #include <Windows.h>
    #include <cstdio>
    
    int main() {
        while (true) {
            printf("0x%x\n", LOBYTE(VkKeyScanW(0)));
            Sleep(1000);
        }
        return 0;
    }
    
  4. Change the keyboard layout using Win+Space or similar

Expected behavior

VkKeyScanW(0) prints 0x32 if the US and 0x40 if the UK layout is selected. The value changes during runtime if the layout is changed.

Actual behavior

VkKeyScanW(0) will continue to return its initial value and not change if the keyboard layout is changed during runtime. MapVirtualKeyW appears similarly affected. (I haven't tried to reproduce this yet though.)

This has far reaching implications due to the widespread use of these functions in this code base and manifests itself in key combinations either not working at all, or producing incorrect VT sequences. The only way to fix the issue is by restarting the application.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Windows keyboard-layout change with the provided C++ example, then trace the terminal's uses of VkKeyScanW and MapVirtualKeyW. Done means these calls reflect runtime layout changes and affected key combinations produce correct VT sequences without restarting the application.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.