rust-windowing / rust-windowing/winit

Ctrl is reported as not pressed when combining Ctrl+Altgr on Windows

Open
#3,012 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

DS - win32
Dominant language
Rust
Stars
6.2k
Forks
1.3k
Avg merge
2d 19h
Merged PRs (30d)
9

Description

On Windows, when pressing a key in combination with altgr for example ctrl+alt-gr+e, which produces , the CTRL state is not reported correctly. Here's the log from WindowEvent::KeyboardEvent, and WindowEvent::ModifiersChanged

Modifiers { state: ModifiersState(CONTROL), pressed_mods: ModifiersKeys(0x0) }
KeyEvent {
    physical_key: ControlLeft,
    logical_key: Control,
    text: None,
    location: Left,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: None,
        key_without_modifiers: Control,
    },
}
Modifiers { state: ModifiersState(0x0), pressed_mods: ModifiersKeys(0x0) }
KeyEvent {
    physical_key: AltRight,
    logical_key: AltGraph,
    text: None,
    location: Right,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: None,
        key_without_modifiers: AltGraph,
    },
}
KeyEvent {
    physical_key: AltRight,
    logical_key: AltGraph,
    text: None,
    location: Right,
    state: Pressed,
    repeat: true,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: None,
        key_without_modifiers: AltGraph,
    },
}
KeyEvent {
    physical_key: AltRight,
    logical_key: AltGraph,
    text: None,
    location: Right,
    state: Pressed,
    repeat: true,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: None,
        key_without_modifiers: AltGraph,
    },
}
KeyEvent {
    physical_key: AltRight,
    logical_key: AltGraph,
    text: None,
    location: Right,
    state: Pressed,
    repeat: true,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: None,
        key_without_modifiers: AltGraph,
    },
}
KeyEvent {
    physical_key: AltRight,
    logical_key: AltGraph,
    text: None,
    location: Right,
    state: Pressed,
    repeat: true,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: None,
        key_without_modifiers: AltGraph,
    },
}
KeyEvent {
    physical_key: KeyE,
    logical_key: Character(
        "€",
    ),
    text: Some(
        "€",
    ),
    location: Standard,
    state: Pressed,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: Some(
            "€",
        ),
        key_without_modifiers: Character(
            "e",
        ),
    },
}
KeyEvent {
    physical_key: KeyE,
    logical_key: Character(
        "€",
    ),
    text: None,
    location: Standard,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: None,
        key_without_modifiers: Character(
            "e",
        ),
    },
}
Modifiers { state: ModifiersState(CONTROL), pressed_mods: ModifiersKeys(0x0) }
KeyEvent {
    physical_key: AltRight,
    logical_key: AltGraph,
    text: None,
    location: Right,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: None,
        key_without_modifiers: AltGraph,
    },
}
Modifiers { state: ModifiersState(0x0), pressed_mods: ModifiersKeys(0x0) }
KeyEvent {
    physical_key: ControlLeft,
    logical_key: Control,
    text: None,
    location: Left,
    state: Released,
    repeat: false,
    platform_specific: KeyEventExtra {
        text_with_all_modifers: None,
        key_without_modifiers: Control,
    },
}

As soon as AltGraph is pressed Modifiers::state stops reporting Control, and only starts reporting it again when AltGr is released. Therefore, it's impossible to determine that control is held down using the modifiers state alone.

Note that there's also another, not as critical bug shown in the logs, AltGraph is repeated, although I don't think there should be a key repeat on that since it's a modifier, I'm not even sure if it makes sense to report it as a key press at all, rather than a modifier state.

This was reproduced using Neovide and Winit 0.29.0-beta.0

I think a similar issue was reported by @dhardy here in this comment https://github.com/rust-windowing/winit/issues/2898#issuecomment-1662679926

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

Reproduce the Ctrl+AltGr sequence on Windows and inspect the logged WindowEvent::KeyboardEvent and ModifiersChanged output. Compare the behavior with the related discussion in issue #2898; done means Control remains represented in modifier state while AltGraph is held and AltGraph does not produce inappropriate repeats.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.