Winit: On macOS, releasing a key while holding command does not send event

Created on 9 Aug 2018  路  4Comments  路  Source: rust-windowing/winit

When I press and released a key, while holding the command key, on macOS (10.13.3) - I get the pressed event, but no corresponding released event. When not holding the command key (even if other modifier keys are held) the released event appears to fire correctly.

Steps to reproduce:

  1. Run cargo run --example window
  2. Hold the command key
  3. Press and release the H (or any other) key twice

Expected result:

There should be two released events printed to the console, in between the pressed events.

Actual result:

No release events are sent:

WindowEvent { window_id: WindowId(Id(140272942043600)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 4, state: Pressed, virtual_keycode: Some(H), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: true } } } }
WindowEvent { window_id: WindowId(Id(140272942043600)), event: ReceivedCharacter('h') }
WindowEvent { window_id: WindowId(Id(140272942043600)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 4, state: Pressed, virtual_keycode: Some(H), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: true } } } }
WindowEvent { window_id: WindowId(Id(140272942043600)), event: ReceivedCharacter('h') }

I git bisected and got dec728cfa28547f17c650dd945d5d2b73086f879 as the first commit with the issue - hopefully that helps.

macOS help wanted needs investigation bug

Most helpful comment

I'm currently not working on keyboard-handling code, but when I do (maybe in a week or so), I might give this a shot.

All 4 comments

I can reproduce this on macOS 10.13 with master (b2b740f) when I press "Cmd-P" (Cmd down, P down, P up, Cmd up):

WindowEvent { window_id: ..., event: KeyboardInput { device_id: ..., input: KeyboardInput { scancode: 55, state: Pressed, virtual_keycode: Some(RWin), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: true } } } }
WindowEvent { window_id: ..., event: KeyboardInput { device_id: ..., input: KeyboardInput { scancode: 35, state: Pressed, virtual_keycode: Some(P), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: true } } } }
WindowEvent { window_id: ..., event: ReceivedCharacter('p') }
WindowEvent { window_id: ..., event: KeyboardInput { device_id: ..., input: KeyboardInput { scancode: 55, state: Released, virtual_keycode: Some(RWin), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } } }

Which is: Cmd-pressed, P-pressed, P-received, Cmd-released.

Expected: Cmd-pressed, P-pressed, P-received, P-released, Cmd-released.

(RWin and LWin are weird too btw., especially as I'm pressing the opposite Cmd: LeftCmd = RWin and RightCmd = LWin. Separate issue.)

When I press just P (P down, P up), I get:

WindowEvent { window_id: ..., event: KeyboardInput { device_id: ..., input: KeyboardInput { scancode: 35, state: Pressed, virtual_keycode: Some(P), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } } }
WindowEvent { window_id: ..., event: ReceivedCharacter('p') }
WindowEvent { window_id: ..., event: KeyboardInput { device_id: ..., input: KeyboardInput { scancode: 35, state: Released, virtual_keycode: Some(P), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } } }

Which is as expected: P-pressed, P-received, P-released.

I see the same issue with LeftCmd being RWin and vice-versa. I can open a separate issue for that if it would be helpful.

I'm currently not working on keyboard-handling code, but when I do (maybe in a week or so), I might give this a shot.

y'all mind trying this branch: https://github.com/tomaka/winit/pull/629 ?

It doesn't fix the switched Lcmd/Rwin thing, but it seems to fix the key release event. I couldn't find any adverse side effects, but any more testing would be appreciated.

Was this page helpful?
0 / 5 - 0 ratings