microsoft / microsoft/terminal
VkKeyScanW(0) is a constant during runtime independent of keyboard layout changes
Nobody has claimed this yet.
- 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
- Add the "US" keyboard layout within the "English (United States)" language
- Add the "United Kingdom Extended" layout within the "English (United Kingdom)" language
- 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; } - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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