Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(win/input): use active keyboard layout for non-normalized key events #3125

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/platform/windows/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,16 @@
auto &ki = i.ki;

// If the client did not normalize this VK code to a US English layout, we can't accurately convert it to a scancode.
bool send_scancode = !(flags & SS_KBE_FLAG_NON_NORMALIZED) || config::input.always_send_scancodes;

if (send_scancode) {
// If we're set to always send scancodes, we will use the current keyboard layout to convert to a scancode. This will
// assume the client and host have the same keyboard layout, but it's probably better than always using US English.
if (!(flags & SS_KBE_FLAG_NON_NORMALIZED)) {
// Mask off the extended key byte
ki.wScan = VK_TO_SCANCODE_MAP[modcode & 0xFF];
}
else if (config::input.always_send_scancodes && modcode != VK_LWIN && modcode != VK_RWIN && modcode != VK_PAUSE) {
// For some reason, MapVirtualKey(VK_LWIN, MAPVK_VK_TO_VSC) doesn't seem to work :/
ki.wScan = MapVirtualKey(modcode, MAPVK_VK_TO_VSC);

Check warning on line 629 in src/platform/windows/input.cpp

View check run for this annotation

Codecov / codecov/patch

src/platform/windows/input.cpp#L629

Added line #L629 was not covered by tests
}

// If we can map this to a scancode, send it as a scancode for maximum game compatibility.
if (ki.wScan) {
Expand Down
Loading