Skip to content

Keyboard input not captured on latest macOS system #1822

@luojia65

Description

@luojia65

I recently updated my macOS Catalina to 10.15.2. I wrote my code like:

use glium::*;

fn main() {
    let mut event_loop = glutin::EventsLoop::new();
    let wb = glutin::WindowBuilder::new();
    let cb = glutin::ContextBuilder::new().with_depth_buffer(24);
    let _display = glium::Display::new(wb, cb, &event_loop).unwrap();

    event_loop.run_forever(|ev| match ev {
        glutin::Event::WindowEvent { event, .. } => match event {
            glutin::WindowEvent::CloseRequested => winit::ControlFlow::Break,
            glutin::WindowEvent::KeyboardInput {
                device_id, input: kin
            } => {
                println!("WindowEvent Key: {:?} DeviceId: {:?}", kin, device_id);
                winit::ControlFlow::Continue
            }
            _ => winit::ControlFlow::Continue,
        },
        glutin::Event::DeviceEvent { event, device_id } => match event {
            glutin::DeviceEvent::Key(kin) => {
                println!("DeviceEvent Key: {:?} DeviceId: {:?}", kin, device_id);
                winit::ControlFlow::Continue
            },
            _ => winit::ControlFlow::Continue
        },
        _ => winit::ControlFlow::Continue
    });
}

And there is a window shown as expected. When I try to press a key, I expect both WindowEvent and DeviceEvent could print an output.

However, only WindowEvent did. The whole output is like:

WindowEvent Key: KeyboardInput { scancode: 18, state: Pressed, virtual_keycode: Some(Key1), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } DeviceId: DeviceId(DeviceId)
WindowEvent Key: KeyboardInput { scancode: 19, state: Pressed, virtual_keycode: Some(Key2), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } DeviceId: DeviceId(DeviceId)
WindowEvent Key: KeyboardInput { scancode: 18, state: Released, virtual_keycode: Some(Key1), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } DeviceId: DeviceId(DeviceId)
WindowEvent Key: KeyboardInput { scancode: 20, state: Pressed, virtual_keycode: Some(Key3), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } DeviceId: DeviceId(DeviceId)

What happened? Should there also be a DeviceEvent output?
I used glium = "0.25.1".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions