Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot receive Xbox One S controller(gamepad) key events #3416

Closed
nomyfan opened this issue Jan 24, 2024 · 1 comment
Closed

Cannot receive Xbox One S controller(gamepad) key events #3416

nomyfan opened this issue Jan 24, 2024 · 1 comment

Comments

@nomyfan
Copy link

nomyfan commented Jan 24, 2024

I wonder if it's well supported. It only received an event when Xbox button released(RawKeyEvent and KeyboardInput).
Tested on Windows 10.

Here is my example code

use winit::{
    event::{DeviceEvent, Event, RawKeyEvent, WindowEvent},
    event_loop::EventLoop,
    window::WindowBuilder,
};

fn main() -> Result<(), impl std::error::Error> {
    let event_loop = EventLoop::new().unwrap();

    let window = WindowBuilder::new()
        .with_title("A fantastic window!")
        .with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0))
        .build(&event_loop)
        .unwrap();

    event_loop.run(move |event, elwt| {
        //
        match event {
            Event::WindowEvent { window_id, event } => match event {
                WindowEvent::KeyboardInput {
                    device_id,
                    event,
                    is_synthetic,
                } => {
                    println!("[KEYBOARD_EVENT] {:?}", event)
                }
                WindowEvent::CloseRequested => {
                    elwt.exit();
                }
                _ => {}
            },
            Event::DeviceEvent {
                device_id,
                event: device_event,
            } => match device_event {
                DeviceEvent::Button { button, state } => {
                    println!("[BUTTON] {:?} state {:?}", button, state);
                }
                DeviceEvent::Key(RawKeyEvent {
                    physical_key,
                    state,
                }) => {
                    println!("[PHYSICAL] key {:?} state {:?}", physical_key, state);
                }
                _ => {}
            },
            _ => {}
        }
    })
}
@kchibisov
Copy link
Member

gamepads are not supported yet #944.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants