-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Added keyboard scan input event #5495
Conversation
also i added |
Is there a need for the enum? Couldn't we just pass around the raw |
I don't know, this is the most obvious approach for me
Maybe, but i'm very new to rust, like, i'm two weeks into it for now |
No worries, glad you're contributing already. It's a great way to learn! 😄 I’d say we could replace the enum with |
Ok, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on board with this direction. While it's not a full fix, it's the obviously correct next step (and a change I was considering making already).
I would say this probably closes both #2052 and #862 (please mention this in the PR description), but we'll want to make more targeted follow-up issues for things like text input and keyboard button visualization (for input binding menus and prompts).
Co-authored-by: Alice Cecile <[email protected]>
crates/bevy_input/src/keyboard.rs
Outdated
/// | ||
/// It is used as the generic `T` value of an [`Input`](crate::Input) to create a `Res<Input<ScanCode>>`. | ||
/// The resource stores the numeration of the buttons of a keyboard and can be accessed inside of a system. | ||
/// Use [`KeyCode`](KeyCode) for more meaningful/readable code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this captures the distinction quite correctly. ScanCodes are used for semantic values, KeyCodes correspond to the position on a keyboard. We should also update KeyCode
's docs to link back to here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See for example https://wiki.libsdl.org/CategoryKeyboard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mixed up the two
SDL_Scancode values are used to represent the physical location of a keyboard key on the keyboard.
SDL_Keycode values are mapped to the current layout of the keyboard
(from the website you linked)
scancode: ScanCode
Identifies the physical key pressed
virtual_keycode: Option<VirtualKeyCode>
Identifies the semantic meaning of the key
https://docs.rs/winit/latest/winit/event/struct.KeyboardInput.html (winit
docs, since Bevy gets KeyboardInput
from it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the right call for now. ScanCode might have some issues (as outlined in #2052), but this is the best interim solution we have / is a pretty standard way of doing things.
bors r+ |
# Objective - I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that ## Solution - I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>` - closes both #2052 and #862 Co-authored-by: Bleb1k <[email protected]>
Pull request successfully merged into main. Build succeeded: |
# Objective - I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that ## Solution - I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>` - closes both bevyengine#2052 and bevyengine#862 Co-authored-by: Bleb1k <[email protected]>
# Objective - I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that ## Solution - I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>` - closes both bevyengine#2052 and bevyengine#862 Co-authored-by: Bleb1k <[email protected]>
# Objective - I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that ## Solution - I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>` - closes both bevyengine#2052 and bevyengine#862 Co-authored-by: Bleb1k <[email protected]>
# Objective - I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that ## Solution - I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>` - closes both bevyengine#2052 and bevyengine#862 Co-authored-by: Bleb1k <[email protected]>
Objective
Solution
ScanCode
enum with two hundreds scan codes and updatedkeyboard_input_system
to include and updateResMut<Input<ScanCode>>