Honor Shift, Ctrl and Alt bindings in native mouse mode #4627

Open
F0RLE wants to merge 1 commit from upstream-pr/4627 into main
F0RLE commented 2026-12-01 00:10:34 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by F0RLE on 2026-12-01T00:10:34Z.


Refs #3801

What it changes

In native mouse mode, Windows reports left and right modifiers separately. A binding such as A = Shift in the existing bindings.ini therefore misses both physical Shift keys.

Match either side for plain Shift, Ctrl and Alt, and suppress the corresponding stock button so a remapped key does not fire both actions. Explicit left/right bindings still affect only that side. Left Shift and Left Ctrl retain vehicle pitch when the binding is generic. No config migration is needed.

How it was tested

  • cargo test --release --locked --offline -j 2 -p victory-hle --lib on 4999167b: 471 passed, 13 ignored. Includes regression tests for both sides, stock-button suppression and vehicle pitch.
  • cargo xtask policy: passed. No in-game test on this commit.

Checked for overlap

  • Searched open PRs for the same issue and for the file this touches. #4588 changes prompts, #3055 handles Native.* overrides, and #4586 changes the shipped layout. This patch fixes generic modifiers in existing unprefixed bindings on main.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5576168001 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4627). Originally posted by [F0RLE](https://github.com/F0RLE) on 2026-12-01T00:10:34Z. --- Refs #3801 ## What it changes In native mouse mode, Windows reports left and right modifiers separately. A binding such as `A = Shift` in the existing `bindings.ini` therefore misses both physical Shift keys. Match either side for plain `Shift`, `Ctrl` and `Alt`, and suppress the corresponding stock button so a remapped key does not fire both actions. Explicit left/right bindings still affect only that side. Left Shift and Left Ctrl retain vehicle pitch when the binding is generic. No config migration is needed. ## How it was tested - `cargo test --release --locked --offline -j 2 -p victory-hle --lib` on `4999167b`: 471 passed, 13 ignored. Includes regression tests for both sides, stock-button suppression and vehicle pitch. - `cargo xtask policy`: passed. No in-game test on this commit. ## Checked for overlap - [x] Searched open PRs for the same issue and for the file this touches. #4588 changes prompts, #3055 handles `Native.*` overrides, and #4586 changes the shipped layout. This patch fixes generic modifiers in existing unprefixed bindings on `main`.
Trillazill commented 2026-12-01 07:15:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Trillazill on 2026-12-01T07:15:18Z.


A layout problem in the lines this PR rewrites, which it keeps ("Keep both physical-position and virtual-key matching"): on a non-US layout a bound letter also fires by its US position.

On a French AZERTY keyboard the key labelled Q sits where a US keyboard has A (scan 0x1E), so pad_key reports it as A. With the commenter's file in #4536 (MoveLeft = Q, A = A), pressing Q also presses what A = A binds. That is the "Q is the rear brake at the same time" there. The same mix-up lets the table's button at a key's place fire for a key the file binds by label: the A key (US Q position) also presses the table's LB.

bindings.ini names keys by their label (F1 KEY BINDINGS writes the virtual key that was pressed), so a bound key should count by virtual_key alone. A test on this branch shows it, with KeyState { scan_code: 0x1E, virtual_key: b'Q' } and bindings [(b'A', A)]:

assertion `left == right` failed: Q (bound to MoveLeft) presses the A button
  left: 4
 right: 0

Suggested change in stand_in_buttons. It keeps your generic-modifier handling and only drops the positional match for bound keys:

let bound_key = |k: &KeyState| {
    bound.iter().any(|&(key, _)| key == k.virtual_key || generic_modifier_matches(key, k.virtual_key))
};
let stock = FALLBACK_BUTTONS
    .iter()
    .filter(|&&(vk, _)| {
        !(driving && matches!(vk, 0xA0..=0xA3)) && keys.iter().any(|k| pad_key(k) == vk && !bound_key(k))
    })
    .fold(0, |all, (_, bit)| all | bit);
bound.iter().fold(stock, |all, &(vk, bit)| {
    let pressed = keys.iter().any(|k| {
        k.virtual_key == vk
            || (!(driving && matches!(k.virtual_key, 0xA0 | 0xA2))
                && generic_modifier_matches(vk, k.virtual_key))
    });
    if pressed { all | bit } else { all }
})

On US layouts this gives the same buttons, since a letter's position and label agree there. With it, cargo test -p victory-hle --lib -- gameinput:: passes 99 (2 ignored), including your modifier tests and the AZERTY one above. I couldn't check it in game: the game's key-file input reports letters at US positions, so AZERTY can't be played through it. I can push it to a branch if that's easier to pick up.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7303830694 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4627#issuecomment-7303830694). Originally posted by [Trillazill](https://github.com/Trillazill) on 2026-12-01T07:15:18Z. --- A layout problem in the lines this PR rewrites, which it keeps ("Keep both physical-position and virtual-key matching"): on a non-US layout a bound letter also fires by its US position. On a French AZERTY keyboard the key labelled **Q** sits where a US keyboard has A (scan 0x1E), so `pad_key` reports it as `A`. With the commenter's file in #4536 (`MoveLeft = Q`, `A = A`), pressing Q also presses what `A = A` binds. That is the "Q is the rear brake at the same time" there. The same mix-up lets the table's button at a key's place fire for a key the file binds by label: the A key (US Q position) also presses the table's LB. `bindings.ini` names keys by their label (F1 KEY BINDINGS writes the virtual key that was pressed), so a bound key should count by `virtual_key` alone. A test on this branch shows it, with `KeyState { scan_code: 0x1E, virtual_key: b'Q' }` and bindings `[(b'A', A)]`: ``` assertion `left == right` failed: Q (bound to MoveLeft) presses the A button left: 4 right: 0 ``` Suggested change in `stand_in_buttons`. It keeps your generic-modifier handling and only drops the positional match for bound keys: ```rust let bound_key = |k: &KeyState| { bound.iter().any(|&(key, _)| key == k.virtual_key || generic_modifier_matches(key, k.virtual_key)) }; let stock = FALLBACK_BUTTONS .iter() .filter(|&&(vk, _)| { !(driving && matches!(vk, 0xA0..=0xA3)) && keys.iter().any(|k| pad_key(k) == vk && !bound_key(k)) }) .fold(0, |all, (_, bit)| all | bit); bound.iter().fold(stock, |all, &(vk, bit)| { let pressed = keys.iter().any(|k| { k.virtual_key == vk || (!(driving && matches!(k.virtual_key, 0xA0 | 0xA2)) && generic_modifier_matches(vk, k.virtual_key)) }); if pressed { all | bit } else { all } }) ``` On US layouts this gives the same buttons, since a letter's position and label agree there. With it, `cargo test -p victory-hle --lib -- gameinput::` passes 99 (2 ignored), including your modifier tests and the AZERTY one above. I couldn't check it in game: the game's key-file input reports letters at US positions, so AZERTY can't be played through it. I can push it to a branch if that's easier to pick up.
andrewpozdnakov7-jpg commented 2026-12-01 09:14:59 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T09:14:59Z.


I applied Trillazill's suggested fix on the exact PR head 4999167b. Explicit button bindings now use the key label from the active layout. A held key already claimed by a binding skips its stock button. Unbound buttons keep their positional defaults. Review commit

The new Windows/MSVC regression reproduced the extra A button bit (4) for the Q key on AZERTY. With 36f66ad0ccb32e3e1fea69715c0a8e2dfb236e61, Q no longer emits A, the key labelled A emits only its bound button, and removing the binding restores the positional shoulder button. The two existing modifier tests passed, including generic Shift/Ctrl/Alt and vehicle pitch, and cargo xtask policy --staged accepted the one-file change.

This is the button-activation part of #4536. It is ready to cherry-pick into this PR with its Git author and co-author preserved. A run on the reporter's AZERTY setup is still needed.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7306427480 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4627#issuecomment-7306427480). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-12-01T09:14:59Z. --- I applied Trillazill's [suggested fix](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4627#issuecomment-7303830694) on the exact PR head `4999167b`. Explicit button bindings now use the key label from the active layout. A held key already claimed by a binding skips its stock button. Unbound buttons keep their positional defaults. [Review commit](https://github.com/andrewpozdnakov7-jpg/VIctory-NVIDIA/commit/36f66ad0ccb32e3e1fea69715c0a8e2dfb236e61) The new Windows/MSVC regression reproduced the extra A button bit (4) for the Q key on AZERTY. With `36f66ad0ccb32e3e1fea69715c0a8e2dfb236e61`, Q no longer emits A, the key labelled A emits only its bound button, and removing the binding restores the positional shoulder button. The two existing modifier tests passed, including generic Shift/Ctrl/Alt and vehicle pitch, and `cargo xtask policy --staged` accepted the one-file change. This is the button-activation part of #4536. It is ready to cherry-pick into this PR with its Git author and co-author preserved. A run on the reporter's AZERTY setup is still needed. AI-assisted with OpenAI Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/4627:upstream-pr/4627'
git switch 'upstream-pr/4627'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/4627'
git switch 'upstream-pr/4627'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/4627'
git switch 'upstream-pr/4627'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/4627'
git switch 'main'
git merge --squash 'upstream-pr/4627'
git switch 'main'
git merge --ff-only 'upstream-pr/4627'
git switch 'main'
git merge 'upstream-pr/4627'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!4627
No description provided.