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

Derive Serialize/Deserialize for VirtualKeyCode #654

Closed
kerskuchen opened this issue Sep 15, 2018 · 1 comment
Closed

Derive Serialize/Deserialize for VirtualKeyCode #654

kerskuchen opened this issue Sep 15, 2018 · 1 comment

Comments

@kerskuchen
Copy link

kerskuchen commented Sep 15, 2018

It would be useful for VirtualKeyCode (and possibly other structs in event.rs) to be serializable/deserializable to write and read in custom key-mapping files that can be consumed directly by applications.

For example this would allow for serialized HashMaps like

(
    key_mapping: {
        Up: ["ui_up","move_up",],
        Down: ["ui_down","move_down",],
        Left: ["ui_left","move_left",],
        Right: ["ui_right","move_right",],
    },
)

be used by a winit-agnostic process_buttons function like

match event {
    WindowEvent::KeyboardInput {
        input:
            KeyboardInput {
                state: glutin::ElementState::Pressed,
                virtual_keycode: Some(key),
                // modifiers,
                ..
            },
        ..
    } => match key {
        let buttons = key_mapping[key];
        process_buttons(&buttons);
    }
}

without needing to change the event loop.

@kerskuchen
Copy link
Author

I just realized this is a duplicate of #304

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

1 participant