Skip to content

Virtual Keycode is incorrect on macOS non-qwerty layouts #752

@Toqozz

Description

@Toqozz

The virtual_keycode field seems to be incorrect when using a non-qwerty layout. It seems to always return values corresponding to the qwerty (or perhaps physical?) layout.

I'm running the following program:

extern crate winit;

fn main() {
    let mut events_loop = winit::EventsLoop::new();
    let window = winit::Window::new(&events_loop).unwrap();

    events_loop.run_forever(|event| {
        println!("{:?}", event);
        match event {
            winit::Event::WindowEvent {
                event: winit::WindowEvent::CloseRequested, ..
            } => winit::ControlFlow::Break,
            _ => winit::ControlFlow::Continue,
        }
    });
}

Pressing a dvorak P here (qwerty 'R') results in the following lines:

WindowEvent { window_id: WindowId(Id(140217433672064)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 15, state: Pressed, virtual_keycode: Some(R), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } } }

WindowEvent { window_id: WindowId(Id(140217433672064)), event: ReceivedCharacter('p') }

As you can see, we receive virtual_keycode: Some(R). Also note that right after the window receives the P character. (Shouldn't these always be the same?)

The issue doesn't seem to occur on Linux/X11.

winit version: 0.18
MacBook Pro (2017)
macOS version: 10.14 (Mojave)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C - in progressImplementation is proceeding smoothlyDS - appkitAffects the AppKit/macOS backendS - platform parityUnintended platform differences

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions