From c37c17b4455483f97ebab1d83949e171aee7893d Mon Sep 17 00:00:00 2001 From: Shute052 Date: Mon, 19 Feb 2024 23:07:25 +0800 Subject: [PATCH 1/5] Update for Bevy 0.13 --- Cargo.toml | 10 +- README.md | 4 +- RELEASES.md | 18 ++ benches/input_map.rs | 44 ++-- examples/action_state_resource.rs | 2 +- examples/arpg_indirection.rs | 8 +- examples/clash_handling.rs | 10 +- examples/consuming_actions.rs | 4 +- examples/default_controls.rs | 2 +- examples/multiplayer.rs | 12 +- examples/physical_key_bindings.rs | 73 ------- examples/press_duration.rs | 8 +- examples/register_gamepads.rs | 2 +- examples/send_actions_over_network.rs | 2 +- examples/single_player.rs | 16 +- examples/twin_stick_controller.rs | 8 +- examples/ui_driven_actions.rs | 4 +- examples/virtual_dpad.rs | 8 +- src/action_state.rs | 8 +- src/axislike.rs | 31 ++- src/clashing_inputs.rs | 88 ++++---- src/display_impl.rs | 3 +- src/input_map.rs | 16 +- src/input_mocking.rs | 35 ++-- src/input_streams.rs | 60 +++--- src/lib.rs | 2 - src/plugin.rs | 4 +- src/scan_codes/linux.rs | 278 -------------------------- src/scan_codes/mac_os.rs | 234 ---------------------- src/scan_codes/mod.rs | 40 ---- src/scan_codes/wasm.rs | 262 ------------------------ src/scan_codes/windows.rs | 242 ---------------------- src/systems.rs | 26 +-- src/user_input.rs | 63 ++---- tests/clashes.rs | 40 ++-- tests/integration.rs | 29 ++- 36 files changed, 267 insertions(+), 1429 deletions(-) delete mode 100644 examples/physical_key_bindings.rs delete mode 100644 src/scan_codes/linux.rs delete mode 100644 src/scan_codes/mac_os.rs delete mode 100644 src/scan_codes/mod.rs delete mode 100644 src/scan_codes/wasm.rs delete mode 100644 src/scan_codes/windows.rs diff --git a/Cargo.toml b/Cargo.toml index 42dcec8f..3b470cbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,11 +38,12 @@ egui = ['dep:bevy_egui'] [dependencies] leafwing_input_manager_macros = { path = "macros", version = "0.12" } -bevy = { version = "0.12", default-features = false, features = [ +bevy = { version = "0.13", default-features = false, features = [ "serialize", "bevy_gilrs", ] } -bevy_egui = { version = "0.24", optional = true } +# TODO(clean): Existing PR repo for update `bevy_egui` to bevy 0.13 +bevy_egui = { git = "https://github.com/Shute052/bevy_egui.git", branch = "Bevy-0.13-and-Egui-0.26", optional = true } derive_more = { version = "0.99", default-features = false, features = [ "display", @@ -52,7 +53,7 @@ itertools = "0.12" serde = { version = "1.0", features = ["derive"] } [dev-dependencies] -bevy = { version = "0.12", default-features = false, features = [ +bevy = { version = "0.13", default-features = false, features = [ "bevy_asset", "bevy_sprite", "bevy_text", @@ -61,7 +62,8 @@ bevy = { version = "0.12", default-features = false, features = [ "bevy_core_pipeline", "x11", ] } -bevy_egui = { version = "0.24" } +# TODO(clean): Existing PR repo for update `bevy_egui` to bevy 0.13 +bevy_egui = { git = "https://github.com/Shute052/bevy_egui.git", branch = "Bevy-0.13-and-Egui-0.26" } serde_test = "1.0" criterion = "0.5" diff --git a/README.md b/README.md index e203bf39..7456dc5c 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ and a single input can result in multiple actions being triggered, which can be - Ergonomic insertion API that seamlessly blends multiple input types for you - Can't decide between `input_map.insert(Action::Jump, KeyCode::Space)` and `input_map.insert(Action::Jump, GamepadButtonType::South)`? Have both! - Full support for arbitrary button combinations: chord your heart out. - - `input_map.insert_chord(Action::Console, [KeyCode::ControlLeft, KeyCode::Shift, KeyCode::C])` + - `input_map.insert_chord(Action::Console, [KeyCode::ControlLeft, KeyCode::Shift, KeyCode::KeyC])` - Sophisticated input disambiguation with the `ClashStrategy` enum: stop triggering individual buttons when you meant to press a chord! - Create an arbitrary number of strongly typed disjoint action sets by adding multiple copies of this plugin: decouple your camera and player state - Local multiplayer support: freely bind keys to distinct entities, rather than worrying about singular global state - Networked multiplayer support: serializable structs, and a space-conscious `ActionDiff` representation to send on the wire - Powerful and easy-to-use input mocking API for integration testing your Bevy applications - - `app.send_input(KeyCode::B)` or `world.send_input(UserInput::chord([KeyCode::B, KeyCode::E, KeyCode::V, KeyCode::Y])` + - `app.send_input(KeyCode::KeyB)` or `world.send_input(UserInput::chord([KeyCode::KeyB, KeyCode::KeyE, KeyCode::KeyV, KeyCode::KeyY])` - Control which state this plugin is active in: stop wandering around while in a menu! - Leafwing Studio's trademark `#![forbid(missing_docs)]` diff --git a/RELEASES.md b/RELEASES.md index aa704621..15f6e5ec 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,5 +1,23 @@ # Release Notes +## Unreleased + +### Breaking Changes + +- both `KeyCode`-based logical keybindings and `ScanCode`-based physical keybindings are no longer supported; +- please migrate to: + - `KeyCode` is now representing physical keybindings. + - `InputKind::KeyLocation` have been removed; please use `InputKind::PhysicalKey` instead. + - `ScanCode` and `QwertyScanCode` have been removed; please use `KeyCode` instead: + - all letter keys now follow the format `KeyCode::Key`, e.g., `ScanCode::K` is now `KeyCode::KeyK`. + - all number keys over letters now follow the format `KeyCode::Digit`, e.g., `ScanCode::Key1` is now `KeyCode::Digit1`. + - all arrow keys now follow the format `KeyCode::Arrow`, e.g., `ScanCode::Up` is now `KeyCode::ArrowUp`. + +### Usability + +- `bevy` dependency has been bumped from 0.12 to 0.13. +- `bevy_egui` dependency has been bumped from 0.24 to 0.25. + ## Version 0.12.1 ### Usability diff --git a/benches/input_map.rs b/benches/input_map.rs index 3d4ad05a..4a4bf470 100644 --- a/benches/input_map.rs +++ b/benches/input_map.rs @@ -28,32 +28,32 @@ enum TestAction { fn construct_input_map_from_iter() -> InputMap { black_box(InputMap::new([ - (TestAction::A, KeyCode::A), - (TestAction::B, KeyCode::B), - (TestAction::C, KeyCode::C), - (TestAction::D, KeyCode::D), - (TestAction::E, KeyCode::E), - (TestAction::F, KeyCode::F), - (TestAction::G, KeyCode::G), - (TestAction::H, KeyCode::H), - (TestAction::I, KeyCode::I), - (TestAction::J, KeyCode::J), + (TestAction::A, KeyCode::KeyA), + (TestAction::B, KeyCode::KeyB), + (TestAction::C, KeyCode::KeyC), + (TestAction::D, KeyCode::KeyD), + (TestAction::E, KeyCode::KeyE), + (TestAction::F, KeyCode::KeyF), + (TestAction::G, KeyCode::KeyG), + (TestAction::H, KeyCode::KeyH), + (TestAction::I, KeyCode::KeyI), + (TestAction::J, KeyCode::KeyJ), ])) } fn construct_input_map_from_chained_calls() -> InputMap { black_box( InputMap::default() - .insert(TestAction::A, KeyCode::A) - .insert(TestAction::B, KeyCode::B) - .insert(TestAction::C, KeyCode::C) - .insert(TestAction::D, KeyCode::D) - .insert(TestAction::E, KeyCode::E) - .insert(TestAction::F, KeyCode::F) - .insert(TestAction::G, KeyCode::G) - .insert(TestAction::H, KeyCode::H) - .insert(TestAction::I, KeyCode::I) - .insert(TestAction::J, KeyCode::J) + .insert(TestAction::A, KeyCode::KeyA) + .insert(TestAction::B, KeyCode::KeyB) + .insert(TestAction::C, KeyCode::KeyC) + .insert(TestAction::D, KeyCode::KeyD) + .insert(TestAction::E, KeyCode::KeyE) + .insert(TestAction::F, KeyCode::KeyF) + .insert(TestAction::G, KeyCode::KeyG) + .insert(TestAction::H, KeyCode::KeyH) + .insert(TestAction::I, KeyCode::KeyI) + .insert(TestAction::J, KeyCode::KeyJ) .build(), ) } @@ -78,8 +78,8 @@ pub fn criterion_benchmark(c: &mut Criterion) { // Constructing our test app / input stream outside of the timed benchmark let mut app = App::new(); app.add_plugins(InputPlugin); - app.send_input(KeyCode::A); - app.send_input(KeyCode::B); + app.send_input(KeyCode::KeyA); + app.send_input(KeyCode::KeyB); app.update(); let input_streams = InputStreams::from_world(&app.world, None); diff --git a/examples/action_state_resource.rs b/examples/action_state_resource.rs index 3d980b30..e8711c36 100644 --- a/examples/action_state_resource.rs +++ b/examples/action_state_resource.rs @@ -30,7 +30,7 @@ impl PlayerAction { fn mkb_input_map() -> InputMap { use KeyCode::*; InputMap::new([ - (Self::Jump, UserInput::Single(InputKind::Keyboard(Space))), + (Self::Jump, UserInput::Single(InputKind::PhysicalKey(Space))), (Self::Move, UserInput::VirtualDPad(VirtualDPad::wasd())), ]) } diff --git a/examples/arpg_indirection.rs b/examples/arpg_indirection.rs index 9af9a61b..7dbf28b7 100644 --- a/examples/arpg_indirection.rs +++ b/examples/arpg_indirection.rs @@ -96,10 +96,10 @@ fn spawn_player(mut commands: Commands) { commands.spawn(PlayerBundle { player: Player, slot_input_map: InputMap::new([ - (Slot::Ability1, Q), - (Slot::Ability2, W), - (Slot::Ability3, E), - (Slot::Ability4, R), + (Slot::Ability1, KeyQ), + (Slot::Ability2, KeyW), + (Slot::Ability3, KeyE), + (Slot::Ability4, KeyR), ]) .insert(Slot::Primary, MouseButton::Left) .insert(Slot::Secondary, MouseButton::Right) diff --git a/examples/clash_handling.rs b/examples/clash_handling.rs index 5f6588ea..da30e63f 100644 --- a/examples/clash_handling.rs +++ b/examples/clash_handling.rs @@ -36,13 +36,13 @@ fn spawn_input_map(mut commands: Commands) { let mut input_map = InputMap::default(); // Setting up input mappings in the obvious way - input_map.insert_multiple([(One, Key1), (Two, Key2), (Three, Key3)]); + input_map.insert_multiple([(One, Digit1), (Two, Digit2), (Three, Digit3)]); - input_map.insert_chord(OneAndTwo, [Key1, Key2]); - input_map.insert_chord(OneAndThree, [Key1, Key3]); - input_map.insert_chord(TwoAndThree, [Key2, Key3]); + input_map.insert_chord(OneAndTwo, [Digit1, Digit2]); + input_map.insert_chord(OneAndThree, [Digit1, Digit3]); + input_map.insert_chord(TwoAndThree, [Digit2, Digit3]); - input_map.insert_chord(OneAndTwoAndThree, [Key1, Key2, Key3]); + input_map.insert_chord(OneAndTwoAndThree, [Digit1, Digit2, Digit3]); commands.spawn(InputManagerBundle { input_map, diff --git a/examples/consuming_actions.rs b/examples/consuming_actions.rs index fd92bde3..c3d5d188 100644 --- a/examples/consuming_actions.rs +++ b/examples/consuming_actions.rs @@ -13,8 +13,8 @@ fn main() { .init_resource::>() .insert_resource(InputMap::::new([ (MenuAction::CloseWindow, KeyCode::Escape), - (MenuAction::OpenMainMenu, KeyCode::M), - (MenuAction::OpenSubMenu, KeyCode::S), + (MenuAction::OpenMainMenu, KeyCode::KeyM), + (MenuAction::OpenSubMenu, KeyCode::KeyS), ])) .init_resource::() .init_resource::() diff --git a/examples/default_controls.rs b/examples/default_controls.rs index 77fccd56..829c3000 100644 --- a/examples/default_controls.rs +++ b/examples/default_controls.rs @@ -32,7 +32,7 @@ impl PlayerAction { // Match against the provided action to get the correct default keyboard-mouse input match self { Self::Run => UserInput::VirtualDPad(VirtualDPad::wasd()), - Self::Jump => UserInput::Single(InputKind::Keyboard(KeyCode::Space)), + Self::Jump => UserInput::Single(InputKind::PhysicalKey(KeyCode::Space)), Self::UseItem => UserInput::Single(InputKind::Mouse(MouseButton::Left)), } } diff --git a/examples/multiplayer.rs b/examples/multiplayer.rs index b853e3e6..0805812e 100644 --- a/examples/multiplayer.rs +++ b/examples/multiplayer.rs @@ -32,9 +32,9 @@ impl PlayerBundle { fn input_map(player: Player) -> InputMap { let mut input_map = match player { Player::One => InputMap::new([ - (Action::Left, KeyCode::A), - (Action::Right, KeyCode::D), - (Action::Jump, KeyCode::W), + (Action::Left, KeyCode::KeyA), + (Action::Right, KeyCode::KeyD), + (Action::Jump, KeyCode::KeyW), ]) // This is a quick and hacky solution: // you should coordinate with the `Gamepads` resource to determine the correct gamepad for each player @@ -44,9 +44,9 @@ impl PlayerBundle { .set_gamepad(Gamepad { id: 0 }) .build(), Player::Two => InputMap::new([ - (Action::Left, KeyCode::Left), - (Action::Right, KeyCode::Right), - (Action::Jump, KeyCode::Up), + (Action::Left, KeyCode::ArrowLeft), + (Action::Right, KeyCode::ArrowRight), + (Action::Jump, KeyCode::ArrowUp), ]) .set_gamepad(Gamepad { id: 1 }) .build(), diff --git a/examples/physical_key_bindings.rs b/examples/physical_key_bindings.rs deleted file mode 100644 index 1e5055b9..00000000 --- a/examples/physical_key_bindings.rs +++ /dev/null @@ -1,73 +0,0 @@ -//! For some controls, such as the classical WASD movement controls, -//! we don't care about the actual output of the keys, but rather where they are positioned. -//! -//! For example, on the French AZERTY keyboard layout, these keys are not in the standard triangle pattern, -//! so using them for player movement would feel very awkward. -//! -//! Instead, we can base our bindings on the physical position of the keys. -//! This functionality is provided by _scan codes_. -//! -//! In order to not deal with arbitrary numbers to define the key positions, -//! we can use [`QwertyScanCode`] to define the name of the keys on the US QWERTY layout. -//! The mapping to the other keyboard layouts is done automatically. - -use bevy::prelude::*; -use leafwing_input_manager::prelude::*; - -fn main() { - App::new() - .add_plugins(DefaultPlugins) - .add_plugins(InputManagerPlugin::::default()) - // The InputMap and ActionState components will be added to any entity with the Player component - .add_systems(Startup, spawn_player) - // Read the ActionState in your systems using queries! - .add_systems(Update, jump) - .run(); -} - -// This is the list of "things in the game I want to be able to do based on input" -#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)] -enum Action { - Forward, - Left, - Backward, - Right, -} - -#[derive(Component)] -struct Player; - -fn spawn_player(mut commands: Commands) { - commands - .spawn(InputManagerBundle:: { - // Stores "which actions are currently pressed" - action_state: ActionState::default(), - // We define the name of the keys based on the US QWERTY layout. - // The keys the user will actually have to press depends on their selected keyboard layout. - // However, the _position_ of the keys will be the same, regardless of layout. - // This way, every player can use the classic triangle shaped key arrangement. - input_map: InputMap::new([ - (Action::Forward, QwertyScanCode::W), - (Action::Left, QwertyScanCode::A), - (Action::Backward, QwertyScanCode::S), - (Action::Right, QwertyScanCode::D), - ]), - }) - .insert(Player); -} - -// Query for the `ActionState` component in your game logic systems! -fn jump(query: Query<&ActionState, With>) { - let action_state = query.single(); - - // Each action has a button-like state of its own that you can check - if action_state.just_pressed(&Action::Forward) { - println!("Going forward!"); - } else if action_state.just_pressed(&Action::Left) { - println!("Going left!"); - } else if action_state.just_pressed(&Action::Backward) { - println!("Going backward!"); - } else if action_state.just_pressed(&Action::Right) { - println!("Going right!"); - } -} diff --git a/examples/press_duration.rs b/examples/press_duration.rs index 060772c4..4c9f1c0c 100644 --- a/examples/press_duration.rs +++ b/examples/press_duration.rs @@ -47,10 +47,10 @@ impl PlayerBundle { use Action::*; InputMap::new([ - (Left, KeyCode::A), - (Left, KeyCode::Left), - (Right, KeyCode::D), - (Right, KeyCode::Right), + (Left, KeyCode::KeyA), + (Left, KeyCode::ArrowLeft), + (Right, KeyCode::KeyD), + (Right, KeyCode::ArrowRight), ]) } } diff --git a/examples/register_gamepads.rs b/examples/register_gamepads.rs index 257bf554..5b47c41a 100644 --- a/examples/register_gamepads.rs +++ b/examples/register_gamepads.rs @@ -32,7 +32,7 @@ fn join( mut commands: Commands, mut joined_players: ResMut, gamepads: Res, - button_inputs: Res>, + button_inputs: Res>, ) { for gamepad in gamepads.iter() { // Join the game when both bumpers (L+R) on the controller are pressed diff --git a/examples/send_actions_over_network.rs b/examples/send_actions_over_network.rs index 525ea12d..6975570d 100644 --- a/examples/send_actions_over_network.rs +++ b/examples/send_actions_over_network.rs @@ -127,7 +127,7 @@ fn spawn_player(mut commands: Commands) { commands .spawn(InputManagerBundle { - input_map: InputMap::new([(MoveLeft, W), (MoveRight, D), (Jump, Space)]) + input_map: InputMap::new([(MoveLeft, KeyW), (MoveRight, KeyD), (Jump, Space)]) .insert(Shoot, MouseButton::Left) .build(), ..default() diff --git a/examples/single_player.rs b/examples/single_player.rs index fab76380..f7310d74 100644 --- a/examples/single_player.rs +++ b/examples/single_player.rs @@ -74,34 +74,34 @@ impl PlayerBundle { let mut input_map = InputMap::default(); // Movement - input_map.insert(Up, KeyCode::Up); + input_map.insert(Up, KeyCode::ArrowUp); input_map.insert(Up, GamepadButtonType::DPadUp); - input_map.insert(Down, KeyCode::Down); + input_map.insert(Down, KeyCode::ArrowDown); input_map.insert(Down, GamepadButtonType::DPadDown); - input_map.insert(Left, KeyCode::Left); + input_map.insert(Left, KeyCode::ArrowLeft); input_map.insert(Left, GamepadButtonType::DPadLeft); - input_map.insert(Right, KeyCode::Right); + input_map.insert(Right, KeyCode::ArrowRight); input_map.insert(Right, GamepadButtonType::DPadRight); // Abilities - input_map.insert(Ability1, KeyCode::Q); + input_map.insert(Ability1, KeyCode::KeyQ); input_map.insert(Ability1, GamepadButtonType::West); input_map.insert(Ability1, MouseButton::Left); - input_map.insert(Ability2, KeyCode::W); + input_map.insert(Ability2, KeyCode::KeyW); input_map.insert(Ability2, GamepadButtonType::North); input_map.insert(Ability2, MouseButton::Right); - input_map.insert(Ability3, KeyCode::E); + input_map.insert(Ability3, KeyCode::KeyE); input_map.insert(Ability3, GamepadButtonType::East); input_map.insert(Ability4, KeyCode::Space); input_map.insert(Ability4, GamepadButtonType::South); - input_map.insert(Ultimate, KeyCode::R); + input_map.insert(Ultimate, KeyCode::KeyR); input_map.insert(Ultimate, GamepadButtonType::LeftTrigger2); input_map diff --git a/examples/twin_stick_controller.rs b/examples/twin_stick_controller.rs index 18c1c6bd..c14e4805 100644 --- a/examples/twin_stick_controller.rs +++ b/examples/twin_stick_controller.rs @@ -83,8 +83,8 @@ pub struct InputModeManagerPlugin; impl Plugin for InputModeManagerPlugin { fn build(&self, app: &mut App) { - // Add a state to record the current active input - app.add_state::() + // Init a state to record the current active input + app.init_state::() // System to switch to gamepad as active input .add_systems( Update, @@ -156,7 +156,9 @@ fn player_mouse_look( if let Some(p) = window .cursor_position() .and_then(|cursor| camera.viewport_to_world(camera_transform, cursor)) - .and_then(|ray| Some(ray).zip(ray.intersect_plane(player_transform.translation, Vec3::Y))) + .and_then(|ray| { + Some(ray).zip(ray.intersect_plane(player_transform.translation, Plane3d::new(Vec3::Y))) + }) .map(|(ray, p)| ray.get_point(p)) { let diff = (p - player_transform.translation).xz(); diff --git a/examples/ui_driven_actions.rs b/examples/ui_driven_actions.rs index 44698576..9e285f5e 100644 --- a/examples/ui_driven_actions.rs +++ b/examples/ui_driven_actions.rs @@ -25,8 +25,8 @@ struct Player; fn spawn_player(mut commands: Commands) { let mut input_map = InputMap::default(); - input_map.insert(Action::Left, KeyCode::Left); - input_map.insert(Action::Right, KeyCode::Right); + input_map.insert(Action::Left, KeyCode::ArrowLeft); + input_map.insert(Action::Right, KeyCode::ArrowRight); commands .spawn(SpriteBundle { diff --git a/examples/virtual_dpad.rs b/examples/virtual_dpad.rs index 8fd780bf..28a8ca04 100644 --- a/examples/virtual_dpad.rs +++ b/examples/virtual_dpad.rs @@ -30,10 +30,10 @@ fn spawn_player(mut commands: Commands) { input_map: InputMap::new([( Action::Move, VirtualDPad { - up: KeyCode::W.into(), - down: KeyCode::S.into(), - left: KeyCode::A.into(), - right: KeyCode::D.into(), + up: KeyCode::KeyW.into(), + down: KeyCode::KeyS.into(), + left: KeyCode::KeyA.into(), + right: KeyCode::KeyD.into(), }, )]) .build(), diff --git a/src/action_state.rs b/src/action_state.rs index 5136eb09..46686b9e 100644 --- a/src/action_state.rs +++ b/src/action_state.rs @@ -101,7 +101,7 @@ impl ActionState { /// Updates the [`ActionState`] based on a vector of [`ActionData`], ordered by [`Actionlike::id`](Actionlike). /// /// The `action_data` is typically constructed from [`InputMap::which_pressed`](crate::input_map::InputMap), - /// which reads from the assorted [`Input`](bevy::input::Input) resources. + /// which reads from the assorted [`ButtonInput`](bevy::input::ButtonInput) resources. pub fn update(&mut self, action_data: HashMap) { for (action, action_datum) in action_data { match self.action_data.entry(action) { @@ -614,7 +614,7 @@ mod tests { // Input map let mut input_map = InputMap::default(); - input_map.insert(Action::Run, KeyCode::R); + input_map.insert(Action::Run, KeyCode::KeyR); // Starting state let input_streams = InputStreams::from_world(&app.world, None); @@ -626,7 +626,7 @@ mod tests { assert!(!action_state.just_released(&Action::Run)); // Pressing - app.send_input(KeyCode::R); + app.send_input(KeyCode::KeyR); // Process the input events into Input data app.update(); let input_streams = InputStreams::from_world(&app.world, None); @@ -648,7 +648,7 @@ mod tests { assert!(!action_state.just_released(&Action::Run)); // Releasing - app.release_input(KeyCode::R); + app.release_input(KeyCode::KeyR); app.update(); let input_streams = InputStreams::from_world(&app.world, None); diff --git a/src/axislike.rs b/src/axislike.rs index f4ae365d..8123c3cd 100644 --- a/src/axislike.rs +++ b/src/axislike.rs @@ -2,7 +2,6 @@ use crate::buttonlike::{MouseMotionDirection, MouseWheelDirection}; use crate::orientation::{Direction, Rotation}; -use crate::prelude::QwertyScanCode; use crate::user_input::InputKind; use bevy::input::{ gamepad::{GamepadAxisType, GamepadButtonType}, @@ -366,10 +365,10 @@ impl VirtualDPad { /// Generates a [`VirtualDPad`] corresponding to the arrow keyboard keycodes pub fn arrow_keys() -> VirtualDPad { VirtualDPad { - up: InputKind::Keyboard(KeyCode::Up), - down: InputKind::Keyboard(KeyCode::Down), - left: InputKind::Keyboard(KeyCode::Left), - right: InputKind::Keyboard(KeyCode::Right), + up: InputKind::PhysicalKey(KeyCode::ArrowUp), + down: InputKind::PhysicalKey(KeyCode::ArrowDown), + left: InputKind::PhysicalKey(KeyCode::ArrowLeft), + right: InputKind::PhysicalKey(KeyCode::ArrowRight), } } @@ -381,10 +380,10 @@ impl VirtualDPad { /// which enables comfortable movement controls. pub fn wasd() -> VirtualDPad { VirtualDPad { - up: InputKind::KeyLocation(QwertyScanCode::W.into()), - down: InputKind::KeyLocation(QwertyScanCode::S.into()), - left: InputKind::KeyLocation(QwertyScanCode::A.into()), - right: InputKind::KeyLocation(QwertyScanCode::D.into()), + up: InputKind::PhysicalKey(KeyCode::KeyW), + down: InputKind::PhysicalKey(KeyCode::KeyS), + left: InputKind::PhysicalKey(KeyCode::KeyA), + right: InputKind::PhysicalKey(KeyCode::KeyD), } } @@ -467,32 +466,32 @@ pub struct VirtualAxis { impl VirtualAxis { /// Helper function for generating a [`VirtualAxis`] from arbitrary keycodes, shorthand for - /// wrapping each key in [`InputKind::Keyboard`] + /// wrapping each key in [`InputKind::PhysicalKey`] pub fn from_keys(negative: KeyCode, positive: KeyCode) -> VirtualAxis { VirtualAxis { - negative: InputKind::Keyboard(negative), - positive: InputKind::Keyboard(positive), + negative: InputKind::PhysicalKey(negative), + positive: InputKind::PhysicalKey(positive), } } /// Generates a [`VirtualAxis`] corresponding to the horizontal arrow keyboard keycodes pub fn horizontal_arrow_keys() -> VirtualAxis { - VirtualAxis::from_keys(KeyCode::Left, KeyCode::Right) + VirtualAxis::from_keys(KeyCode::ArrowLeft, KeyCode::ArrowRight) } /// Generates a [`VirtualAxis`] corresponding to the horizontal arrow keyboard keycodes pub fn vertical_arrow_keys() -> VirtualAxis { - VirtualAxis::from_keys(KeyCode::Down, KeyCode::Up) + VirtualAxis::from_keys(KeyCode::ArrowDown, KeyCode::ArrowUp) } /// Generates a [`VirtualAxis`] corresponding to the `AD` keyboard keycodes. pub fn ad() -> VirtualAxis { - VirtualAxis::from_keys(KeyCode::A, KeyCode::D) + VirtualAxis::from_keys(KeyCode::KeyA, KeyCode::KeyD) } /// Generates a [`VirtualAxis`] corresponding to the `WS` keyboard keycodes. pub fn ws() -> VirtualAxis { - VirtualAxis::from_keys(KeyCode::S, KeyCode::W) + VirtualAxis::from_keys(KeyCode::KeyS, KeyCode::KeyW) } #[allow(clippy::doc_markdown)] diff --git a/src/clashing_inputs.rs b/src/clashing_inputs.rs index 20a3cafa..ff75bb61 100644 --- a/src/clashing_inputs.rs +++ b/src/clashing_inputs.rs @@ -376,24 +376,24 @@ mod tests { let mut input_map = InputMap::default(); - input_map.insert(One, Key1); - input_map.insert(Two, Key2); - input_map.insert_chord(OneAndTwo, [Key1, Key2]); - input_map.insert_chord(TwoAndThree, [Key2, Key3]); - input_map.insert_chord(OneAndTwoAndThree, [Key1, Key2, Key3]); - input_map.insert_chord(CtrlOne, [ControlLeft, Key1]); - input_map.insert_chord(AltOne, [AltLeft, Key1]); - input_map.insert_chord(CtrlAltOne, [ControlLeft, AltLeft, Key1]); + input_map.insert(One, Digit1); + input_map.insert(Two, Digit2); + input_map.insert_chord(OneAndTwo, [Digit1, Digit2]); + input_map.insert_chord(TwoAndThree, [Digit2, Digit3]); + input_map.insert_chord(OneAndTwoAndThree, [Digit1, Digit2, Digit3]); + input_map.insert_chord(CtrlOne, [ControlLeft, Digit1]); + input_map.insert_chord(AltOne, [AltLeft, Digit1]); + input_map.insert_chord(CtrlAltOne, [ControlLeft, AltLeft, Digit1]); input_map.insert( MoveDPad, VirtualDPad { - up: Up.into(), - down: Down.into(), - left: Left.into(), - right: Right.into(), + up: ArrowUp.into(), + down: ArrowDown.into(), + left: ArrowLeft.into(), + right: ArrowRight.into(), }, ); - input_map.insert_chord(CtrlUp, [ControlLeft, Up]); + input_map.insert_chord(CtrlUp, [ControlLeft, ArrowUp]); input_map } @@ -408,33 +408,33 @@ mod tests { #[test] fn clash_detection() { - let a: UserInput = A.into(); - let b: UserInput = B.into(); - let c: UserInput = C.into(); - let ab = UserInput::chord([A, B]); - let bc = UserInput::chord([B, C]); - let abc = UserInput::chord([A, B, C]); + let a: UserInput = KeyA.into(); + let b: UserInput = KeyB.into(); + let c: UserInput = KeyC.into(); + let ab = UserInput::chord([KeyA, KeyB]); + let bc = UserInput::chord([KeyB, KeyC]); + let abc = UserInput::chord([KeyA, KeyB, KeyC]); let axyz_dpad: UserInput = VirtualDPad { - up: A.into(), - down: X.into(), - left: Y.into(), - right: Z.into(), + up: KeyA.into(), + down: KeyX.into(), + left: KeyY.into(), + right: KeyZ.into(), } .into(); let abcd_dpad: UserInput = VirtualDPad { - up: A.into(), - down: B.into(), - left: C.into(), - right: D.into(), + up: KeyA.into(), + down: KeyB.into(), + left: KeyC.into(), + right: KeyD.into(), } .into(); - let ctrl_up: UserInput = UserInput::chord([Up, ControlLeft]); + let ctrl_up: UserInput = UserInput::chord([ArrowUp, ControlLeft]); let directions_dpad: UserInput = VirtualDPad { - up: Up.into(), - down: Down.into(), - left: Left.into(), - right: Right.into(), + up: ArrowUp.into(), + down: ArrowDown.into(), + left: ArrowLeft.into(), + right: ArrowRight.into(), } .into(); @@ -458,8 +458,8 @@ mod tests { let correct_clash = Clash { action_a: One, action_b: OneAndTwo, - inputs_a: vec![Key1.into()], - inputs_b: vec![UserInput::chord([Key1, Key2])], + inputs_a: vec![Digit1.into()], + inputs_b: vec![UserInput::chord([Digit1, Digit2])], }; assert_eq!(observed_clash, correct_clash); @@ -475,8 +475,8 @@ mod tests { let correct_clash = Clash { action_a: OneAndTwoAndThree, action_b: OneAndTwo, - inputs_a: vec![UserInput::chord([Key1, Key2, Key3])], - inputs_b: vec![UserInput::chord([Key1, Key2])], + inputs_a: vec![UserInput::chord([Digit1, Digit2, Digit3])], + inputs_b: vec![UserInput::chord([Digit1, Digit2])], }; assert_eq!(observed_clash, correct_clash); @@ -502,8 +502,8 @@ mod tests { let input_map = test_input_map(); let simple_clash = input_map.possible_clash(&One, &OneAndTwo).unwrap(); - app.send_input(Key1); - app.send_input(Key2); + app.send_input(Digit1); + app.send_input(Digit2); app.update(); let input_streams = InputStreams::from_world(&app.world, None); @@ -530,7 +530,7 @@ mod tests { let chord_clash = input_map .possible_clash(&OneAndTwo, &OneAndTwoAndThree) .unwrap(); - app.send_input(Key3); + app.send_input(Digit3); app.update(); let input_streams = InputStreams::from_world(&app.world, None); @@ -551,8 +551,8 @@ mod tests { app.add_plugins(InputPlugin); let input_map = test_input_map(); - app.send_input(Key1); - app.send_input(Key2); + app.send_input(Digit1); + app.send_input(Digit2); app.update(); let mut action_data = HashMap::new(); @@ -583,7 +583,7 @@ mod tests { let input_map = test_input_map(); app.send_input(ControlLeft); - app.send_input(Up); + app.send_input(ArrowUp); app.update(); let mut action_data = HashMap::new(); @@ -610,8 +610,8 @@ mod tests { app.add_plugins(InputPlugin); let input_map = test_input_map(); - app.send_input(Key1); - app.send_input(Key2); + app.send_input(Digit1); + app.send_input(Digit2); app.send_input(ControlLeft); app.update(); diff --git a/src/display_impl.rs b/src/display_impl.rs index 0e66fa4c..1783bbf8 100644 --- a/src/display_impl.rs +++ b/src/display_impl.rs @@ -39,9 +39,8 @@ impl Display for InputKind { InputKind::Mouse(button) => write!(f, "{button:?}"), InputKind::MouseWheel(button) => write!(f, "{button:?}"), InputKind::MouseMotion(button) => write!(f, "{button:?}"), - InputKind::Keyboard(button) => write!(f, "{button:?}"), // TODO: We probably want to display the key on the currently active layout - InputKind::KeyLocation(scan_code) => write!(f, "{scan_code:?}"), + InputKind::PhysicalKey(key_code) => write!(f, "{key_code:?}"), InputKind::Modifier(button) => write!(f, "{button:?}"), } } diff --git a/src/input_map.rs b/src/input_map.rs index fbf0665f..c19ce45a 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -61,9 +61,9 @@ let mut input_map = InputMap::new([ input_map.insert(Action::Run, MouseButton::Left) .insert(Action::Run, KeyCode::ShiftLeft) // Chords -.insert_modified(Action::Run, Modifier::Control, KeyCode::R) +.insert_modified(Action::Run, Modifier::Control, KeyCode::KeyR) .insert_chord(Action::Run, - [InputKind::Keyboard(KeyCode::H), + [InputKind::PhysicalKey(KeyCode::KeyH), InputKind::GamepadButton(GamepadButtonType::South), InputKind::Mouse(MouseButton::Middle)], ); @@ -513,17 +513,15 @@ mod tests { let mut input_map_1 = InputMap::::default(); input_map_1.insert(Action::Run, KeyCode::Space); - input_map_1.insert(Action::Run, KeyCode::Return); + input_map_1.insert(Action::Run, KeyCode::Enter); assert_eq!( input_map_1.get(&Action::Run), - Some(&vec![KeyCode::Space.into(), KeyCode::Return.into()]) + Some(&vec![KeyCode::Space.into(), KeyCode::Enter.into()]) ); - let input_map_2 = InputMap::::new([ - (Action::Run, KeyCode::Space), - (Action::Run, KeyCode::Return), - ]); + let input_map_2 = + InputMap::::new([(Action::Run, KeyCode::Space), (Action::Run, KeyCode::Enter)]); assert_eq!(input_map_1, input_map_2); } @@ -576,7 +574,7 @@ mod tests { let mut input_map = InputMap::default(); let mut default_keyboard_map = InputMap::default(); default_keyboard_map.insert(Action::Run, KeyCode::ShiftLeft); - default_keyboard_map.insert_chord(Action::Hide, [KeyCode::ControlLeft, KeyCode::H]); + default_keyboard_map.insert_chord(Action::Hide, [KeyCode::ControlLeft, KeyCode::KeyH]); let mut default_gamepad_map = InputMap::default(); default_gamepad_map.insert(Action::Run, GamepadButtonType::South); default_gamepad_map.insert(Action::Hide, GamepadButtonType::East); diff --git a/src/input_mocking.rs b/src/input_mocking.rs index fb2bd005..489c23b9 100644 --- a/src/input_mocking.rs +++ b/src/input_mocking.rs @@ -19,6 +19,7 @@ use bevy::ecs::world::World; #[cfg(feature = "ui")] use bevy::ecs::{component::Component, query::With, system::Query}; use bevy::input::gamepad::{GamepadAxisChangedEvent, GamepadButtonChangedEvent}; +use bevy::input::keyboard::{Key, NativeKey}; use bevy::input::mouse::MouseScrollUnit; use bevy::input::ButtonState; use bevy::input::{ @@ -26,7 +27,7 @@ use bevy::input::{ keyboard::{KeyCode, KeyboardInput}, mouse::{MouseButton, MouseButtonInput, MouseMotion, MouseWheel}, touch::{TouchInput, Touches}, - Input, + ButtonInput, }; use bevy::math::Vec2; use bevy::prelude::Entity; @@ -50,7 +51,7 @@ use bevy::window::CursorMoved; /// app.add_plugins(InputPlugin); /// /// // Pay respects! -/// app.send_input(KeyCode::F); +/// app.send_input(KeyCode::KeyF); /// app.update(); /// ``` /// @@ -63,7 +64,7 @@ use bevy::window::CursorMoved; /// app.add_plugins(InputPlugin); /// /// // Send inputs one at a time -/// let B_E_V_Y = [KeyCode::B, KeyCode::E, KeyCode::V, KeyCode::Y]; +/// let B_E_V_Y = [KeyCode::KeyB, KeyCode::KeyE, KeyCode::KeyV, KeyCode::KeyY]; /// /// for letter in B_E_V_Y { /// app.send_input(letter); @@ -76,7 +77,7 @@ use bevy::window::CursorMoved; pub trait MockInput { /// Send the specified `user_input` directly /// - /// These are sent as the raw input events, and do not set the value of [`Input`] or [`Axis`](bevy::input::Axis) directly. + /// These are sent as the raw input events, and do not set the value of [`ButtonInput`] or [`Axis`](bevy::input::Axis) directly. /// Note that inputs will continue to be pressed until explicitly released or [`MockInput::reset_inputs`] is called. /// /// To send specific values for axislike inputs, set their `value` field. @@ -88,7 +89,7 @@ pub trait MockInput { /// /// You *must* call `app.update()` at least once after sending input /// with `InputPlugin` included in your plugin set - /// for the raw input events to be processed into [`Input`] and [`Axis`](bevy::input::Axis) data. + /// for the raw input events to be processed into [`ButtonInput`] and [`Axis`](bevy::input::Axis) data. fn send_input(&mut self, input: impl Into); /// Send the specified `user_input` directly, using the specified gamepad @@ -111,7 +112,7 @@ pub trait MockInput { /// Clears all user input streams, resetting them to their default state /// - /// All buttons are released, and `just_pressed` and `just_released` information on the [`Input`] type are lost. + /// All buttons are released, and `just_pressed` and `just_released` information on the [`ButtonInput`] type are lost. /// `just_pressed` and `just_released` on the [`ActionState`](crate::action_state::ActionState) will be kept. /// /// This will clear all [`KeyCode`], [`GamepadButton`] and [`MouseButton`] input streams, @@ -119,20 +120,20 @@ pub trait MockInput { fn reset_inputs(&mut self); } -/// Query [`Input`] state directly for testing purposes. +/// Query [`ButtonInput`] state directly for testing purposes. /// /// In game code, you should (almost) always be using [`ActionState`](crate::action_state::ActionState) /// methods instead. pub trait QueryInput { /// Is the provided `user_input` pressed? /// - /// This method is intended as a convenience for testing; check the [`Input`] resource directly, + /// This method is intended as a convenience for testing; check the [`ButtonInput`] resource directly, /// or use an [`InputMap`](crate::input_map::InputMap) in real code. fn pressed(&self, input: impl Into) -> bool; /// Is the provided `user_input` pressed for the provided [`Gamepad`]? /// - /// This method is intended as a convenience for testing; check the [`Input`] resource directly, + /// This method is intended as a convenience for testing; check the [`ButtonInput`] resource directly, /// or use an [`InputMap`](crate::input_map::InputMap) in real code. fn pressed_for_gamepad(&self, input: impl Into, gamepad: Option) -> bool; } @@ -259,10 +260,10 @@ impl MockInput for MutableInputStreams<'_> { impl MutableInputStreams<'_> { fn send_keyboard_input(&mut self, button_state: ButtonState, raw_inputs: &RawInputs) { - for button in raw_inputs.keycodes.iter() { + for key_code in raw_inputs.keycodes.iter() { self.keyboard_events.send(KeyboardInput { - scan_code: u32::MAX, - key_code: Some(*button), + logical_key: Key::Unidentified(NativeKey::Unidentified), + key_code: *key_code, state: button_state, window: Entity::PLACEHOLDER, }); @@ -346,9 +347,9 @@ impl MockInput for World { } let mut input_system_state: SystemState<( - Option>>, - Option>>, - Option>>, + Option>>, + Option>>, + Option>>, )> = SystemState::new(self); let (maybe_gamepad, maybe_keyboard, maybe_mouse) = input_system_state.get_mut(self); @@ -478,7 +479,7 @@ mod test { app.update(); // Verify that checking the resource value directly works - let keyboard_input: &Input = app.world.resource(); + let keyboard_input: &ButtonInput = app.world.resource(); assert!(keyboard_input.pressed(KeyCode::Space)); // Test the convenient .pressed API @@ -517,7 +518,7 @@ mod test { // Checking the old-fashioned way // FIXME: put this in a gamepad_button.rs integration test. - let gamepad_input = app.world.resource::>(); + let gamepad_input = app.world.resource::>(); assert!(gamepad_input.pressed(GamepadButton { gamepad, button_type: GamepadButtonType::North, diff --git a/src/input_streams.rs b/src/input_streams.rs index 9c590728..3f999abf 100644 --- a/src/input_streams.rs +++ b/src/input_streams.rs @@ -4,9 +4,9 @@ use bevy::ecs::prelude::{Event, Events, ResMut, World}; use bevy::ecs::system::SystemState; use bevy::input::{ gamepad::{Gamepad, GamepadAxis, GamepadButton, GamepadEvent, Gamepads}, - keyboard::{KeyCode, KeyboardInput, ScanCode}, + keyboard::{KeyCode, KeyboardInput}, mouse::{MouseButton, MouseButtonInput, MouseMotion, MouseWheel}, - Axis, Input, + Axis, ButtonInput, }; use bevy::math::Vec2; use bevy::utils::HashSet; @@ -19,25 +19,23 @@ use crate::buttonlike::{MouseMotionDirection, MouseWheelDirection}; use crate::prelude::DualAxis; use crate::user_input::{InputKind, UserInput}; -/// A collection of [`Input`] structs, which can be used to update an [`InputMap`](crate::input_map::InputMap). +/// A collection of [`ButtonInput`] structs, which can be used to update an [`InputMap`](crate::input_map::InputMap). /// /// These are typically collected via a system from the [`World`] as resources. #[derive(Debug, Clone)] pub struct InputStreams<'a> { - /// A [`GamepadButton`] [`Input`] stream - pub gamepad_buttons: &'a Input, + /// A [`GamepadButton`] [`Input`](ButtonInput) stream + pub gamepad_buttons: &'a ButtonInput, /// A [`GamepadButton`] [`Axis`] stream pub gamepad_button_axes: &'a Axis, /// A [`GamepadAxis`] [`Axis`] stream pub gamepad_axes: &'a Axis, /// A list of registered gamepads pub gamepads: &'a Gamepads, - /// A [`KeyCode`] [`Input`] stream - pub keycodes: Option<&'a Input>, - /// A [`ScanCode`] [`Input`] stream - pub scan_codes: Option<&'a Input>, - /// A [`MouseButton`] [`Input`] stream - pub mouse_buttons: Option<&'a Input>, + /// A [`KeyCode`] [`ButtonInput`] stream + pub keycodes: Option<&'a ButtonInput>, + /// A [`MouseButton`] [`Input`](ButtonInput) stream + pub mouse_buttons: Option<&'a ButtonInput>, /// A [`MouseWheel`] event stream pub mouse_wheel: Option>, /// A [`MouseMotion`] event stream @@ -50,13 +48,12 @@ pub struct InputStreams<'a> { impl<'a> InputStreams<'a> { /// Construct an [`InputStreams`] from a [`World`] pub fn from_world(world: &'a World, gamepad: Option) -> Self { - let gamepad_buttons = world.resource::>(); + let gamepad_buttons = world.resource::>(); let gamepad_button_axes = world.resource::>(); let gamepad_axes = world.resource::>(); let gamepads = world.resource::(); - let keycodes = world.get_resource::>(); - let scan_codes = world.get_resource::>(); - let mouse_buttons = world.get_resource::>(); + let keycodes = world.get_resource::>(); + let mouse_buttons = world.get_resource::>(); let mouse_wheel = world.resource::>(); let mouse_motion = world.resource::>(); @@ -69,7 +66,6 @@ impl<'a> InputStreams<'a> { gamepad_axes, gamepads, keycodes, - scan_codes, mouse_buttons, mouse_wheel: Some(mouse_wheel), mouse_motion, @@ -120,12 +116,9 @@ impl<'a> InputStreams<'a> { button_type, }) }), - InputKind::Keyboard(keycode) => { + InputKind::PhysicalKey(keycode) => { matches!(self.keycodes, Some(keycodes) if keycodes.pressed(keycode)) } - InputKind::KeyLocation(scan_code) => { - matches!(self.scan_codes, Some(scan_codes) if scan_codes.pressed(scan_code)) - } InputKind::Modifier(modifier) => { let key_codes = modifier.key_codes(); // Short circuiting is probably not worth the branch here @@ -378,14 +371,14 @@ fn collect_events_cloned(events: &Events) -> Vec { events.get_reader().read(events).cloned().collect() } -/// A mutable collection of [`Input`] structs, which can be used for mocking user inputs. +/// A mutable collection of [`ButtonInput`] structs, which can be used for mocking user inputs. /// /// These are typically collected via a system from the [`World`] as resources. // WARNING: If you update the fields of this type, you must also remember to update `InputMocking::reset_inputs`. #[derive(Debug)] pub struct MutableInputStreams<'a> { - /// A [`GamepadButton`] [`Input`] stream - pub gamepad_buttons: &'a mut Input, + /// A [`GamepadButton`] [`Input`](ButtonInput) stream + pub gamepad_buttons: &'a mut ButtonInput, /// A [`GamepadButton`] [`Axis`] stream pub gamepad_button_axes: &'a mut Axis, /// A [`GamepadAxis`] [`Axis`] stream @@ -395,15 +388,13 @@ pub struct MutableInputStreams<'a> { /// Events used for mocking gamepad-related inputs pub gamepad_events: &'a mut Events, - /// A [`KeyCode`] [`Input`] stream - pub keycodes: &'a mut Input, - /// A [`ScanCode`] [`Input`] stream - pub scan_codes: &'a mut Input, + /// A [`KeyCode`] [`ButtonInput`] stream + pub keycodes: &'a mut ButtonInput, /// Events used for mocking keyboard-related inputs pub keyboard_events: &'a mut Events, - /// A [`MouseButton`] [`Input`] stream - pub mouse_buttons: &'a mut Input, + /// A [`MouseButton`] [`Input`](ButtonInput) stream + pub mouse_buttons: &'a mut ButtonInput, /// Events used for mocking [`MouseButton`] inputs pub mouse_button_events: &'a mut Events, /// A [`MouseWheel`] event stream @@ -419,15 +410,14 @@ impl<'a> MutableInputStreams<'a> { /// Construct a [`MutableInputStreams`] from the [`World`] pub fn from_world(world: &'a mut World, gamepad: Option) -> Self { let mut input_system_state: SystemState<( - ResMut>, + ResMut>, ResMut>, ResMut>, ResMut, ResMut>, - ResMut>, - ResMut>, + ResMut>, ResMut>, - ResMut>, + ResMut>, ResMut>, ResMut>, ResMut>, @@ -440,7 +430,6 @@ impl<'a> MutableInputStreams<'a> { gamepads, gamepad_events, keycodes, - scan_codes, keyboard_events, mouse_buttons, mouse_button_events, @@ -455,7 +444,6 @@ impl<'a> MutableInputStreams<'a> { gamepads: gamepads.into_inner(), gamepad_events: gamepad_events.into_inner(), keycodes: keycodes.into_inner(), - scan_codes: scan_codes.into_inner(), keyboard_events: keyboard_events.into_inner(), mouse_buttons: mouse_buttons.into_inner(), mouse_button_events: mouse_button_events.into_inner(), @@ -485,7 +473,6 @@ impl<'a> From> for InputStreams<'a> { gamepad_axes: mutable_streams.gamepad_axes, gamepads: mutable_streams.gamepads, keycodes: Some(mutable_streams.keycodes), - scan_codes: Some(mutable_streams.scan_codes), mouse_buttons: Some(mutable_streams.mouse_buttons), mouse_wheel: Some(collect_events_cloned(mutable_streams.mouse_wheel)), mouse_motion: collect_events_cloned(mutable_streams.mouse_motion), @@ -502,7 +489,6 @@ impl<'a> From<&'a MutableInputStreams<'a>> for InputStreams<'a> { gamepad_axes: mutable_streams.gamepad_axes, gamepads: mutable_streams.gamepads, keycodes: Some(mutable_streams.keycodes), - scan_codes: Some(mutable_streams.scan_codes), mouse_buttons: Some(mutable_streams.mouse_buttons), mouse_wheel: Some(collect_events_cloned(mutable_streams.mouse_wheel)), mouse_motion: collect_events_cloned(mutable_streams.mouse_motion), diff --git a/src/lib.rs b/src/lib.rs index c78d4348..c9113b50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,6 @@ pub mod input_mocking; pub mod input_streams; pub mod orientation; pub mod plugin; -pub mod scan_codes; pub mod systems; pub mod timing; pub mod user_input; @@ -44,7 +43,6 @@ pub mod prelude { #[cfg(feature = "ui")] pub use crate::input_mocking::MockUIInteraction; pub use crate::input_mocking::{MockInput, QueryInput}; - pub use crate::scan_codes::QwertyScanCode; pub use crate::user_input::{Modifier, UserInput}; pub use crate::plugin::InputManagerPlugin; diff --git a/src/plugin.rs b/src/plugin.rs index 858ee47e..5e8ff2aa 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -23,7 +23,7 @@ use bevy::reflect::TypePath; #[cfg(feature = "ui")] use bevy::ui::UiSystem; -/// A [`Plugin`] that collects [`Input`](bevy::input::Input) from disparate sources, producing an [`ActionState`] that can be conveniently checked +/// A [`Plugin`] that collects [`ButtonInput`](bevy::input::ButtonInput) from disparate sources, producing an [`ActionState`] that can be conveniently checked /// /// This plugin needs to be passed in an [`Actionlike`] enum type that you've created for your game. /// Each variant represents a "virtual button" whose state is stored in an [`ActionState`] struct. @@ -48,7 +48,7 @@ use bevy::ui::UiSystem; /// Complete list: /// /// - [`tick_action_state`](crate::systems::tick_action_state), which resets the `pressed` and `just_pressed` fields of the [`ActionState`] each frame -/// - [`update_action_state`](crate::systems::update_action_state), which collects [`Input`](bevy::input::Input) resources to update the [`ActionState`] +/// - [`update_action_state`](crate::systems::update_action_state), which collects [`ButtonInput`](bevy::input::ButtonInput) resources to update the [`ActionState`] /// - [`update_action_state_from_interaction`](crate::systems::update_action_state_from_interaction), for triggering actions from buttons /// - powers the [`ActionStateDriver`](crate::action_driver::ActionStateDriver) component based on an [`Interaction`](bevy::ui::Interaction) component /// - [`release_on_disable`](crate::systems::release_on_disable), which resets action states when [`ToggleActions`] is flipped, to avoid persistent presses. diff --git a/src/scan_codes/linux.rs b/src/scan_codes/linux.rs deleted file mode 100644 index 39abc88b..00000000 --- a/src/scan_codes/linux.rs +++ /dev/null @@ -1,278 +0,0 @@ -//! Helper enum to define scan codes on the QWERTY keyboard layout. - -/// The key locations as defined by the keys on the QWERTY keyboard layout. -/// -/// The [`u32`] representation of this enum are scan codes of the corresponding keys on X-like Linux systems. -/// See . -#[repr(u32)] -pub enum QwertyScanCode { - /// The location of the Escape/Esc key on the QWERTY keyboard layout. - Escape = 1, - /// The location of the `1` key on the QWERTY keyboard layout. - Key1 = 2, - /// The location of the `2` key on the QWERTY keyboard layout. - Key2 = 3, - /// The location of the `3` key on the QWERTY keyboard layout. - Key3 = 4, - /// The location of the `4` key on the QWERTY keyboard layout. - Key4 = 5, - /// The location of the `5` key on the QWERTY keyboard layout. - Key5 = 6, - /// The location of the `6` key on the QWERTY keyboard layout. - Key6 = 7, - /// The location of the `7` key on the QWERTY keyboard layout. - Key7 = 8, - /// The location of the `8` key on the QWERTY keyboard layout. - Key8 = 9, - /// The location of the `9` key on the QWERTY keyboard layout. - Key9 = 10, - /// The location of the `0` key on the QWERTY keyboard layout. - Key0 = 11, - /// The location of the `-` key on the QWERTY keyboard layout. - Minus = 12, - /// The location of the `=` key on the QWERTY keyboard layout. - Equals = 13, - /// The location of the back(space) key on the QWERTY keyboard layout. - Backspace = 14, - /// The location of the tabulator key on the QWERTY keyboard layout. - Tab = 15, - /// The location of the `Q` key on the QWERTY keyboard layout. - Q = 16, - /// The location of the `W` key on the QWERTY keyboard layout. - W = 17, - /// The location of the `E` key on the QWERTY keyboard layout. - E = 18, - /// The location of the `R` key on the QWERTY keyboard layout. - R = 19, - /// The location of the `T` key on the QWERTY keyboard layout. - T = 20, - /// The location of the `Y` key on the QWERTY keyboard layout. - Y = 21, - /// The location of the `U` key on the QWERTY keyboard layout. - U = 22, - /// The location of the `I` key on the QWERTY keyboard layout. - I = 23, - /// The location of the `O` key on the QWERTY keyboard layout. - O = 24, - /// The location of the `P` key on the QWERTY keyboard layout. - P = 25, - /// The location of the `[` key on the QWERTY keyboard layout. - BracketLeft = 26, - /// The location of the `]` key on the QWERTY keyboard layout. - BracketRight = 27, - /// The location of the Enter/Return key on the QWERTY keyboard layout. - Enter = 28, - /// The location of the left Control key on the QWERTY keyboard layout. - ControlLeft = 29, - /// The location of the `A` key on the QWERTY keyboard layout. - A = 30, - /// The location of the `S` key on the QWERTY keyboard layout. - S = 31, - /// The location of the `D` key on the QWERTY keyboard layout. - D = 32, - /// The location of the `F` key on the QWERTY keyboard layout. - F = 33, - /// The location of the `G` key on the QWERTY keyboard layout. - G = 34, - /// The location of the `H` key on the QWERTY keyboard layout. - H = 35, - /// The location of the `J` key on the QWERTY keyboard layout. - J = 36, - /// The location of the `K` key on the QWERTY keyboard layout. - K = 37, - /// The location of the `L` key on the QWERTY keyboard layout. - L = 38, - /// The location of the `;` key on the QWERTY keyboard layout. - SemiColon = 39, - /// The location of the `'` key on the QWERTY keyboard layout. - Apostrophe = 40, - /// The location of the `` ` `` key on the QWERTY keyboard layout. - Backtick = 41, - /// The location of the left Shift key on the QWERTY keyboard layout. - ShiftLeft = 42, - /// The location of the `\` on the QWERTY keyboard layout. - Backslash = 43, - /// The location of the `Z` key on the QWERTY keyboard layout. - Z = 44, - /// The location of the `X` key on the QWERTY keyboard layout. - X = 45, - /// The location of the `C` key on the QWERTY keyboard layout. - C = 46, - /// The location of the `V key on the QWERTY keyboard layout. - V = 47, - /// The location of the `B` key on the QWERTY keyboard layout. - B = 48, - /// The location of the `N` key on the QWERTY keyboard layout. - N = 49, - /// The location of the `M` key on the QWERTY keyboard layout. - M = 50, - /// The location of the `,` key on the QWERTY keyboard layout. - Comma = 51, - /// The location of the `.` key on the QWERTY keyboard layout. - Period = 52, - /// The location of the `/` key on the QWERTY keyboard layout. - Slash = 53, - /// The location of the right Shift key on the QWERTY keyboard layout. - ShiftRight = 54, - /// The location of the `*` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadDivide` on Apple keyboards. - NumpadMultiply = 55, - /// The location of the left Alt key on the QWERTY keyboard layout. - /// Maps to left Option key on Apple keyboards. - AltLeft = 56, - /// The location of the Space key on the QWERTY keyboard layout. - Space = 57, - /// The location of the caps lock key on the QWERTY keyboard layout. - CapsLock = 58, - /// The location of the `F1` key on the QWERTY keyboard layout. - F1 = 59, - /// The location of the `F2` key on the QWERTY keyboard layout. - F2 = 60, - /// The location of the `F3` key on the QWERTY keyboard layout. - F3 = 61, - /// The location of the `F4` key on the QWERTY keyboard layout. - F4 = 62, - /// The location of the `F5` key on the QWERTY keyboard layout. - F5 = 63, - /// The location of the `F6` key on the QWERTY keyboard layout. - F6 = 64, - /// The location of the `F7` key on the QWERTY keyboard layout. - F7 = 65, - /// The location of the `F8` key on the QWERTY keyboard layout. - F8 = 66, - /// The location of the `F9` key on the QWERTY keyboard layout. - F9 = 67, - /// The location of the `F10` key on the QWERTY keyboard layout. - F10 = 68, - /// The location of the Numlock key on the QWERTY keyboard layout. - /// Maps to `NumpadClear` on Apple keyboards. - Numlock = 69, - /// The location of the Scroll / Scroll Lock key on the QWERTY keyboard layout. - /// Maps to the `F14` key on Apple keyboards. - Scroll = 70, - /// The location of the `7` key on the numpad of the QWERTY keyboard layout. - Numpad7 = 71, - /// The location of the `8` key on the numpad of the QWERTY keyboard layout. - Numpad8 = 72, - /// The location of the `9` key on the numpad of the QWERTY keyboard layout. - Numpad9 = 73, - /// The location of the `*` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadMultiply` on Apple keyboards. - NumpadSubtract = 74, - /// The location of the `4` key on the numpad of the QWERTY keyboard layout. - Numpad4 = 75, - /// The location of the `5` key on the numpad of the QWERTY keyboard layout. - Numpad5 = 76, - /// The location of the `6` key on the numpad of the QWERTY keyboard layout. - Numpad6 = 77, - /// The location of the `+` key on the numpad of the QWERTY keyboard layout. - NumpadAdd = 78, - /// The location of the `1` key on the numpad of the QWERTY keyboard layout. - Numpad1 = 79, - /// The location of the `2` key on the numpad of the QWERTY keyboard layout. - Numpad2 = 80, - /// The location of the `3` key on the numpad of the QWERTY keyboard layout. - Numpad3 = 81, - /// The location of the `0` key on the numpad of the QWERTY keyboard layout. - Numpad0 = 82, - /// The location of the `.` key on the numpad of the QWERTY keyboard layout. - NumpadDecimal = 83, - // KEY_ZENKAKUHANKAKU = 85, - // KEY_102ND = 86, - /// The location of the `F11` key on the QWERTY keyboard layout. - F11 = 87, - /// The location of the `F12` key on the QWERTY keyboard layout. - F12 = 88, - // KEY_R0 = 89, - // KEY_KATAKANA = 90, - // KEY_HIRAGANA = 91, - // KEY_HENKAN = 92, - // KEY_KATAKANAHIRAGANA = 93, - // KEY_MUHENKAN = 94, - // KEY_KPJPCOMMA = 95, - /// The location of the Enter key on the numpad of the QWERTY keyboard layout. - NumpadEnter = 96, - /// The location of the right Control key on the QWERTY keyboard layout. - ControlRight = 97, - /// The location of the `/` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadEquals` on Apple keyboards. - NumpadDivide = 98, - /// The location of the Alt+Sysrq key on the QWERTY keyboard layout. - AltSysrq = 99, - /// The location of the right Alt key on the QWERTY keyboard layout. - /// Maps to right Option key on Apple keyboards. - AltRight = 100, - // KEY_LINEFEED = 101, - /// The location of the Home key on the QWERTY keyboard layout. - Home = 102, - /// The location of the Arrow Up key on the QWERTY keyboard layout. - Up = 103, - /// The location of the Page Up key on the QWERTY keyboard layout. - PageUp = 104, - /// The location of the Arrow Left key on the QWERTY keyboard layout. - Left = 105, - /// The location of the Arrow Right key on the QWERTY keyboard layout. - Right = 106, - /// The location of the End key on the QWERTY keyboard layout. - End = 107, - /// The location of the Arrow Down key on the QWERTY keyboard layout. - Down = 108, - /// The location of the Page Down key on the QWERTY keyboard layout. - PageDown = 109, - /// The location of the Insert key on the QWERTY keyboard layout. - /// Maps to the Help key on Apple keyboards. - Insert = 110, - /// The location of the Delete key on the QWERTY keyboard layout. - Delete = 111, - // KEY_MACRO = 112, - // KEY_MUTE = 113, - // KEY_VOLUMEDOWN = 114, - // KEY_VOLUMEDOWN = 115, - /// The location of the Power key on the QWERTY keyboard layout. - Power = 116, - // KEY_KPEQUAL = 117, - // KEY_KPPLUSMINUS = 118, - /// The location of the Pause key on the QWERTY keyboard layout. - /// Maps to the `F15` key on Apple keyboards. - Pause = 119, - // KEY_SCALE = 120, - // KEY_KPCOMMA = 121, - // KEY_HANGEUL = 122, - // KEY_HANJA = 123, - // KEY_YEN = 124, - /// The location of the left Windows key on the QWERTY keyboard layout. - /// Maps to the Command key on Apple keyboards. - SuperLeft = 125, - /// The location of the right Windows key on the QWERTY keyboard layout. - SuperRight = 126, - // KEY_COMPOSE = 127, - // KEY_STOP = 128, - // KEY_AGAIN = 129, - // KEY_PROPS = 130, - // KEY_UNDO = 131, - // KEY_FRONT = 132, - // KEY_COPY = 133, - // KEY_OPEN = 134, - // KEY_PASTE = 135, - // KEY_FIND = 136, - // KEY_CUT = 137, - // KEY_HELP = 138, - /// The location of the Menu key on the QWERTY keyboard layout. - Menu = 139, - // KEY_CALC = 140, - // KEY_SETUP = 141, - /// The location of the Sleep key on the QWERTY keyboard layout. - Sleep = 142, - /// The location of the Wake key on the QWERTY keyboard layout. - Wake = 143, - // Keys to figure out later: - // /// A key not available on the US QWERTY layout. - // /// - // /// This is for example the `#` key on other layouts. - // NonUs1 = 0x00, - // /// The location of the Snapshot / Print Screen key on the QWERTY keyboard layout. - // /// Maps to the `F13` key on Apple keyboards. - // Snapshot = 0xe0_37, - // /// The location of the Ctrl+Break key on the QWERTY keyboard layout. - // CtrlBreak = 0xe0_46, -} diff --git a/src/scan_codes/mac_os.rs b/src/scan_codes/mac_os.rs deleted file mode 100644 index d57b467d..00000000 --- a/src/scan_codes/mac_os.rs +++ /dev/null @@ -1,234 +0,0 @@ -//! Helper enum to define scan codes on the QWERTY keyboard layout. - -/// The key locations as defined by the keys on the QWERTY keyboard layout. -/// -/// The [`u32`] representation of this enum are the Mac OS scan codes of the corresponding keys. -/// See . -#[repr(u32)] -pub enum QwertyScanCode { - /// The location of the `A` key on the QWERTY keyboard layout. - A = 0x00, - /// The location of the `S` key on the QWERTY keyboard layout. - S = 0x01, - /// The location of the `D` key on the QWERTY keyboard layout. - D = 0x02, - /// The location of the `F` key on the QWERTY keyboard layout. - F = 0x03, - /// The location of the `H` key on the QWERTY keyboard layout. - H = 0x04, - /// The location of the `G` key on the QWERTY keyboard layout. - G = 0x05, - /// The location of the `Z` key on the QWERTY keyboard layout. - Z = 0x06, - /// The location of the `X` key on the QWERTY keyboard layout. - X = 0x07, - /// The location of the `C` key on the QWERTY keyboard layout. - C = 0x08, - /// The location of the `V` key on the QWERTY keyboard layout. - V = 0x09, - /// The location of the `B` key on the QWERTY keyboard layout. - B = 0x0b, - /// The location of the `Q` key on the QWERTY keyboard layout. - Q = 0x0c, - /// The location of the `W` key on the QWERTY keyboard layout. - W = 0x0d, - /// The location of the `E` key on the QWERTY keyboard layout. - E = 0x0e, - /// The location of the `R` key on the QWERTY keyboard layout. - R = 0x0f, - /// The location of the `Y` key on the QWERTY keyboard layout. - Y = 0x10, - /// The location of the `T` key on the QWERTY keyboard layout. - T = 0x11, - /// The location of the `1` key on the QWERTY keyboard layout. - Key1 = 0x12, - /// The location of the `2` key on the QWERTY keyboard layout. - Key2 = 0x13, - /// The location of the `3` key on the QWERTY keyboard layout. - Key3 = 0x14, - /// The location of the `4` key on the QWERTY keyboard layout. - Key4 = 0x15, - /// The location of the `6` key on the QWERTY keyboard layout. - Key6 = 0x16, - /// The location of the `5` key on the QWERTY keyboard layout. - Key5 = 0x17, - /// The location of the `=` key on the QWERTY keyboard layout. - Equals = 0x18, - /// The location of the `9` key on the QWERTY keyboard layout. - Key9 = 0x19, - /// The location of the `7` key on the QWERTY keyboard layout. - Key7 = 0x1a, - /// The location of the `-` key on the QWERTY keyboard layout. - Minus = 0x1b, - /// The location of the `8` key on the QWERTY keyboard layout. - Key8 = 0x1c, - /// The location of the `0` key on the QWERTY keyboard layout. - Key0 = 0x1d, - /// The location of the `]` key on the QWERTY keyboard layout. - BracketRight = 0x1e, - /// The location of the `O` key on the QWERTY keyboard layout. - O = 0x1f, - /// The location of the `U` key on the QWERTY keyboard layout. - U = 0x20, - /// The location of the `[` key on the QWERTY keyboard layout. - BracketLeft = 0x21, - /// The location of the `I` key on the QWERTY keyboard layout. - I = 0x22, - /// The location of the `P` key on the QWERTY keyboard layout. - P = 0x23, - /// The location of the `L` key on the QWERTY keyboard layout. - L = 0x25, - /// The location of the `J` key on the QWERTY keyboard layout. - J = 0x26, - /// The location of the `'` key on the QWERTY keyboard layout. - Apostrophe = 0x27, - /// The location of the `K` key on the QWERTY keyboard layout. - K = 0x28, - /// The location of the `;` key on the QWERTY keyboard layout. - SemiColon = 0x29, - /// The location of the `\` on the QWERTY keyboard layout. - Backslash = 0x2a, - /// The location of the `,` key on the QWERTY keyboard layout. - Comma = 0x2b, - /// The location of the `/` key on the QWERTY keyboard layout. - Slash = 0x2c, - /// The location of the `N` key on the QWERTY keyboard layout. - N = 0x2d, - /// The location of the `M` key on the QWERTY keyboard layout. - M = 0x2e, - /// The location of the `.` key on the QWERTY keyboard layout. - Period = 0x2f, - /// The location of the `` ` `` key on the QWERTY keyboard layout. - Backtick = 0x32, - /// The location of the `.` key on the numpad of the QWERTY keyboard layout. - NumpadDecimal = 0x41, - /// The location of the `*` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadMultiply` on Apple keyboards. - NumpadSubtract = 0x43, - /// The location of the `+` key on the numpad of the QWERTY keyboard layout. - NumpadAdd = 0x45, - /// The location of the Numlock key on the QWERTY keyboard layout. - /// Maps to `NumpadClear` on Apple keyboards. - Numlock = 0x47, - /// The location of the `*` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadDivide` on Apple keyboards. - NumpadMultiply = 0x4b, - /// The location of the Enter key on the numpad of the QWERTY keyboard layout. - NumpadEnter = 0x4c, - // This is an extra key on mac keyboards: NumpadSubtract = 0x4e, - /// The location of the `/` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadEquals` on Apple keyboards. - NumpadDivide = 0x51, - /// The location of the `0` key on the numpad of the QWERTY keyboard layout. - Numpad0 = 0x52, - /// The location of the `1` key on the numpad of the QWERTY keyboard layout. - Numpad1 = 0x53, - /// The location of the `2` key on the numpad of the QWERTY keyboard layout. - Numpad2 = 0x54, - /// The location of the `3` key on the numpad of the QWERTY keyboard layout. - Numpad3 = 0x55, - /// The location of the `4` key on the numpad of the QWERTY keyboard layout. - Numpad4 = 0x56, - /// The location of the `5` key on the numpad of the QWERTY keyboard layout. - Numpad5 = 0x57, - /// The location of the `6` key on the numpad of the QWERTY keyboard layout. - Numpad6 = 0x58, - /// The location of the `7` key on the numpad of the QWERTY keyboard layout. - Numpad7 = 0x59, - /// The location of the `8` key on the numpad of the QWERTY keyboard layout. - Numpad8 = 0x5b, - /// The location of the `9` key on the numpad of the QWERTY keyboard layout. - Numpad9 = 0x5c, - /// The location of the Enter/Return key on the QWERTY keyboard layout. - Enter = 0x24, - /// The location of the Tabulator key on the QWERTY keyboard layout. - Tab = 0x30, - /// The location of the space key on the QWERTY keyboard layout. - Space = 0x31, - /// The location of the back(space) key on the QWERTY keyboard layout. - Backspace = 0x33, - /// The location of the Escape/Esc key on the QWERTY keyboard layout. - Escape = 0x35, - /// The location of the left Windows key on the QWERTY keyboard layout. - /// Maps to the left Command key on Apple keyboards. - SuperLeft = 0x37, - /// The location of the left Shift key on the QWERTY keyboard layout. - ShiftLeft = 0x38, - /// The location of the Caps Lock key on the QWERTY keyboard layout. - CapsLock = 0x39, - /// The location of the left Alt key on the QWERTY keyboard layout. - /// Maps to left Option key on Apple keyboards. - AltLeft = 0x3a, - /// The location of the left Control key on the QWERTY keyboard layout. - ControlLeft = 0x3b, - /// The location of the right Shift key on the QWERTY keyboard layout. - ShiftRight = 0x3c, - /// The location of the right Alt key on the QWERTY keyboard layout. - /// Maps to right Option key on Apple keyboards. - AltRight = 0x3d, - /// The location of the right Control key on the QWERTY keyboard layout. - ControlRight = 0x3e, - // This is an extra key on mac keyboards: Function = 0x3f, - // This is an extra key on mac keyboards: F18 = 0x4f, - // This is an extra key on mac keyboards: F19 = 0x50, - // This is an extra key on mac keyboards: F20 = 0x5a, - /// The location of the `F5` key on the QWERTY keyboard layout. - F5 = 0x60, - /// The location of the `F6` key on the QWERTY keyboard layout. - F6 = 0x61, - /// The location of the `F7` key on the QWERTY keyboard layout. - F7 = 0x62, - /// The location of the `F3` key on the QWERTY keyboard layout. - F3 = 0x63, - /// The location of the `F8` key on the QWERTY keyboard layout. - F8 = 0x64, - /// The location of the `F9` key on the QWERTY keyboard layout. - F9 = 0x65, - /// The location of the `F11` key on the QWERTY keyboard layout. - F11 = 0x67, - /// The location of the Snapshot / Print Screen key on the QWERTY keyboard layout. - /// Maps to the `F13` key on Apple keyboards. - Snapshot = 0x69, - // This is an extra key on mac keyboards: F16 = 0x6a, - /// The location of the Scroll / Scroll Lock key on the QWERTY keyboard layout. - /// Maps to the `F14` key on Apple keyboards. - Scroll = 0x6b, - /// The location of the `F10` key on the QWERTY keyboard layout. - F10 = 0x6d, - /// The location of the `F12` key on the QWERTY keyboard layout. - F12 = 0x6f, - /// The location of the Pause key on the QWERTY keyboard layout. - /// Maps to the `F15` key on Apple keyboards. - Pause = 0x71, - /// The location of the Insert key on the QWERTY keyboard layout. - /// Maps to the Help key on Apple keyboards. - Insert = 0xe0_52, - /// The location of the Home key on the QWERTY keyboard layout. - Home = 0x73, - /// The location of the Page Up key on the QWERTY keyboard layout. - PageUp = 0x74, - /// The location of the Delete key on the QWERTY keyboard layout. - Delete = 0x75, - /// The location of the `F4` key on the QWERTY keyboard layout. - F4 = 0x76, - /// The location of the end key on the QWERTY keyboard layout. - End = 0x77, - /// The location of the `F2` key on the QWERTY keyboard layout. - F2 = 0x78, - /// The location of the page down key on the QWERTY keyboard layout. - PageDown = 0x79, - /// The location of the `F1` key on the QWERTY keyboard layout. - F1 = 0x7a, - /// The location of the left arrow key on the QWERTY keyboard layout. - Left = 0x7b, - /// The location of the right arrow key on the QWERTY keyboard layout. - Right = 0x7c, - /// The location of the arrow down key on the QWERTY keyboard layout. - Down = 0x7d, - /// The location of the arrow up key on the QWERTY keyboard layout. - Up = 0x7e, - // Not listed in the provided link, found by manual testing. - /// The location of the right Windows key on the QWERTY keyboard layout. - /// Maps to the right Command key on Apple keyboards. - SuperRight = 0x36, -} diff --git a/src/scan_codes/mod.rs b/src/scan_codes/mod.rs deleted file mode 100644 index cea021c5..00000000 --- a/src/scan_codes/mod.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Helper enums to easily obtain the scan code of a key. -use bevy::prelude::ScanCode; - -// Wasm -#[cfg(target_family = "wasm")] -mod wasm; -#[cfg(target_family = "wasm")] -pub use wasm::QwertyScanCode; - -// MacOs -#[cfg(all(target_os = "macos", not(target_family = "wasm")))] -mod mac_os; -#[cfg(all(target_os = "macos", not(target_family = "wasm")))] -pub use mac_os::QwertyScanCode; - -// Linux -#[cfg(all(target_os = "linux", not(target_os = "macos")))] -mod linux; -#[cfg(all(target_os = "linux", not(target_os = "macos")))] -pub use linux::QwertyScanCode; - -// Windows and other stuff using Set 1 -#[cfg(all( - not(target_family = "wasm"), - not(target_os = "macos"), - not(target_os = "linux") -))] -mod windows; -#[cfg(all( - not(target_family = "wasm"), - not(target_os = "macos"), - not(target_os = "linux") -))] -pub use windows::QwertyScanCode; - -impl From for ScanCode { - fn from(value: QwertyScanCode) -> Self { - ScanCode(value as u32) - } -} diff --git a/src/scan_codes/wasm.rs b/src/scan_codes/wasm.rs deleted file mode 100644 index 29626e12..00000000 --- a/src/scan_codes/wasm.rs +++ /dev/null @@ -1,262 +0,0 @@ -//! Helper enum to define scan codes on the QWERTY keyboard layout. - -/// The key locations as defined by the keys on the QWERTY keyboard layout. -/// -/// The [`u32`] representation of this enum are the `KeyboardEvent.code` values on Wasm. -/// See . -#[repr(u32)] -pub enum QwertyScanCode { - /// The location of the `1` key on the QWERTY keyboard layout. - Key1 = 0x31, - /// The location of the `2` key on the QWERTY keyboard layout. - Key2 = 0x32, - /// The location of the `3` key on the QWERTY keyboard layout. - Key3 = 0x33, - /// The location of the `4` key on the QWERTY keyboard layout. - Key4 = 0x34, - /// The location of the `5` key on the QWERTY keyboard layout. - Key5 = 0x35, - /// The location of the `6` key on the QWERTY keyboard layout. - Key6 = 0x36, - /// The location of the `7` key on the QWERTY keyboard layout. - Key7 = 0x37, - /// The location of the `8` key on the QWERTY keyboard layout. - Key8 = 0x38, - /// The location of the `9` key on the QWERTY keyboard layout. - Key9 = 0x39, - /// The location of the `0` key on the QWERTY keyboard layout. - Key0 = 0x30, - /// The location of the `A` key on the QWERTY keyboard layout. - A = 0x41, - /// The location of the `B` key on the QWERTY keyboard layout. - B = 0x42, - /// The location of the `C` key on the QWERTY keyboard layout. - C = 0x43, - /// The location of the `D` key on the QWERTY keyboard layout. - D = 0x44, - /// The location of the `E` key on the QWERTY keyboard layout. - E = 0x45, - /// The location of the `F` key on the QWERTY keyboard layout. - F = 0x46, - /// The location of the `G` key on the QWERTY keyboard layout. - G = 0x47, - /// The location of the `H` key on the QWERTY keyboard layout. - H = 0x48, - /// The location of the `I` key on the QWERTY keyboard layout. - I = 0x49, - /// The location of the `J` key on the QWERTY keyboard layout. - J = 0x4a, - /// The location of the `K` key on the QWERTY keyboard layout. - K = 0x4b, - /// The location of the `L` key on the QWERTY keyboard layout. - L = 0x4c, - /// The location of the `M` key on the QWERTY keyboard layout. - M = 0x4d, - /// The location of the `N` key on the QWERTY keyboard layout. - N = 0x4e, - /// The location of the `O` key on the QWERTY keyboard layout. - O = 0x4f, - /// The location of the `P` key on the QWERTY keyboard layout. - P = 0x50, - /// The location of the `Q` key on the QWERTY keyboard layout. - Q = 0x51, - /// The location of the `R` key on the QWERTY keyboard layout. - R = 0x52, - /// The location of the `S` key on the QWERTY keyboard layout. - S = 0x53, - /// The location of the `T` key on the QWERTY keyboard layout. - T = 0x54, - /// The location of the `U` key on the QWERTY keyboard layout. - U = 0x55, - /// The location of the `V key on the QWERTY keyboard layout. - V = 0x56, - /// The location of the `W` key on the QWERTY keyboard layout. - W = 0x57, - /// The location of the `X` key on the QWERTY keyboard layout. - X = 0x58, - /// The location of the `Y` key on the QWERTY keyboard layout. - Y = 0x59, - /// The location of the `Z` key on the QWERTY keyboard layout. - Z = 0x5a, - /// The location of the `,` key on the QWERTY keyboard layout. - Comma = 0xbc, - /// The location of the `.` key on the QWERTY keyboard layout. - Period = 0xbe, - /// The location of the `;` key on the QWERTY keyboard layout. - SemiColon = 0xba, - /// The location of the `'` key on the QWERTY keyboard layout. - Apostrophe = 0xde, - /// The location of the `[` key on the QWERTY keyboard layout. - BracketLeft = 0xdb, - /// The location of the `]` key on the QWERTY keyboard layout. - BracketRight = 0xdd, - /// The location of the `` ` `` key on the QWERTY keyboard layout. - Backtick = 0xc0, - /// The location of the `\` on the QWERTY keyboard layout. - Backslash = 0xdc, - /// The location of the `-` key on the QWERTY keyboard layout. - Minus = 0xbd, - /// The location of the `=` key on the QWERTY keyboard layout. - Equals = 0xbb, - /// The location of the left Alt key on the QWERTY keyboard layout. - /// Maps to left Option key on Apple keyboards. - AltLeft = 0x12, - /// The location of the right Alt key on the QWERTY keyboard layout. - /// Maps to right Option key on Apple keyboards. - /// - /// On Wasm, this scan code value maps to the AltGraph key on Linux, if available. - /// Note the platform specific details here: - /// - AltRight = 0xe1, - /// The location of the caps lock key on the QWERTY keyboard layout. - /// - /// On Wasm, note the platform specific details here: - /// - CapsLock = 0x14, - /// The location of the left Control key on the QWERTY keyboard layout. - /// - /// On Wasm, the right Control key has the same scan code, see: - /// - ControlLeft = 0x11, - /// The location of the left Windows key on the QWERTY keyboard layout. - /// Maps to the Command key on Apple keyboards. - /// - /// On Wasm, note the platform specific details here: - /// - SuperLeft = 0x5b, - /// The location of the right Windows key on the QWERTY keyboard layout. - /// - /// On Wasm, note the platform specific details here: - /// - SuperRight = 0x5c, - /// The location of the left Shift key on the QWERTY keyboard layout. - /// - /// On Wasm, the right Shift key has the same scan code, see: - /// - ShiftLeft = 0x10, - - /// The location of the Menu key on the QWERTY keyboard layout. - /// - /// On Wasm, note the platform specific details here: - /// - Menu = 0x5d, - /// The location of the Enter/Return key on the QWERTY keyboard layout. - Enter = 0x0d, - /// The location of the Space key on the QWERTY keyboard layout. - Space = 0x20, - /// The location of the tabulator key on the QWERTY keyboard layout. - Tab = 0x09, - /// The location of the Delete key on the QWERTY keyboard layout. - Delete = 0x2e, - /// The location of the End key on the QWERTY keyboard layout. - End = 0x23, - // Help = 0x2d, Not available on a lot of platforms and the scan code varies a lot - /// The location of the Home key on the QWERTY keyboard layout. - Home = 0x24, - /// The location of the Insert key on the QWERTY keyboard layout. - /// Maps to the Help key on Apple keyboards. - Insert = 0x2d, - /// The location of the Page Down key on the QWERTY keyboard layout. - PageDown = 0x22, - /// The location of the Page Up key on the QWERTY keyboard layout. - PageUp = 0x21, - /// The location of the Arrow Down key on the QWERTY keyboard layout. - Down = 0x28, - /// The location of the Arrow Left key on the QWERTY keyboard layout. - Left = 0x25, - /// The location of the Arrow Right key on the QWERTY keyboard layout. - Right = 0x27, - /// The location of the Arrow Up key on the QWERTY keyboard layout. - Up = 0x26, - /// The location of the Escape/Esc key on the QWERTY keyboard layout. - Escape = 0x1b, - /// The location of the Snapshot / Print Screen key on the QWERTY keyboard layout. - /// Maps to the `F13` key on Apple keyboards. - /// - /// On Wasm, note the platform specific details here: - /// - Snapshot = 0x2c, - /// The location of the Scroll / Scroll Lock key on the QWERTY keyboard layout. - /// Maps to the `F14` key on Apple keyboards. - /// - /// On Wasm, note the platform specific details here: - /// - Scroll = 0x91, - /// The location of the Pause key on the QWERTY keyboard layout. - /// Maps to the `F15` key on Apple keyboards. - /// - /// On Wasm, note the platform specific details here: - /// - Pause = 0x13, - - /// The location of the `F1` key on the QWERTY keyboard layout. - F1 = 0x70, - /// The location of the `F2` key on the QWERTY keyboard layout. - F2 = 0x71, - /// The location of the `F3` key on the QWERTY keyboard layout. - F3 = 0x72, - /// The location of the `F4` key on the QWERTY keyboard layout. - F4 = 0x73, - /// The location of the `F5` key on the QWERTY keyboard layout. - F5 = 0x74, - /// The location of the `F6` key on the QWERTY keyboard layout. - F6 = 0x75, - /// The location of the `F7` key on the QWERTY keyboard layout. - F7 = 0x76, - /// The location of the `F8` key on the QWERTY keyboard layout. - F8 = 0x77, - /// The location of the `F9` key on the QWERTY keyboard layout. - F9 = 0x78, - /// The location of the `F10` key on the QWERTY keyboard layout. - F10 = 0x79, - /// The location of the `F11` key on the QWERTY keyboard layout. - F11 = 0x7a, - /// The location of the `F12` key on the QWERTY keyboard layout. - F12 = 0x7b, - // F13-F24: Ignoring for now as I'm not sure what they are equivalent to on Windows - /// The location of the Numlock key on the QWERTY keyboard layout. - /// Maps to `NumpadClear` on Apple keyboards. - /// - /// On Wasm, note the platform specific details here: - /// - Numlock = 0x90, - /// The location of the `0` key on the numpad of the QWERTY keyboard layout. - Numpad0 = 0x06, - /// The location of the `1` key on the numpad of the QWERTY keyboard layout. - Numpad1 = 0x61, - /// The location of the `2` key on the numpad of the QWERTY keyboard layout. - Numpad2 = 0x62, - /// The location of the `3` key on the numpad of the QWERTY keyboard layout. - Numpad3 = 0x63, - /// The location of the `4` key on the numpad of the QWERTY keyboard layout. - Numpad4 = 0x64, - /// The location of the `5` key on the numpad of the QWERTY keyboard layout. - Numpad5 = 0x65, - /// The location of the `6` key on the numpad of the QWERTY keyboard layout. - Numpad6 = 0x66, - /// The location of the `7` key on the numpad of the QWERTY keyboard layout. - Numpad7 = 0x67, - /// The location of the `8` key on the numpad of the QWERTY keyboard layout. - Numpad8 = 0x68, - /// The location of the `9` key on the numpad of the QWERTY keyboard layout. - Numpad9 = 0x69, - /// The location of the `+` key on the numpad of the QWERTY keyboard layout. - NumpadAdd = 0x6b, - // NumpadComma = 0xc2: No idea what the difference to NumpadDecimal is. - /// The location of the `.` key on the numpad of the QWERTY keyboard layout. - /// - /// On Wasm, note the platform specific details here: - /// - NumpadDecimal = 0x6e, - /// The location of the `/` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadEquals` on Apple keyboards. - NumpadDivide = 0x6f, - // NumpadEnter = 0x0d, This is the same as `Enter` on Wasm - // NumpadEqual = 0x0c: No idea what the difference to NumpadEnter is. - /// The location of the `*` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadDivide` on Apple keyboards. - NumpadMultiply = 0x6a, - /// The location of the `*` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadMultiply` on Apple keyboards. - NumpadSubtract = 0x6d, -} diff --git a/src/scan_codes/windows.rs b/src/scan_codes/windows.rs deleted file mode 100644 index 5758cb31..00000000 --- a/src/scan_codes/windows.rs +++ /dev/null @@ -1,242 +0,0 @@ -//! Helper enum to define scan codes on the QWERTY keyboard layout. - -/// The key locations as defined by the keys on the QWERTY keyboard layout. -/// -/// The [`u32`] representation of this enum are the Set 1 scan codes of the corresponding keys. -/// See section 10.6 at . -#[repr(u32)] -pub enum QwertyScanCode { - /// The location of the `` ` `` key on the QWERTY keyboard layout. - Backtick = 0x29, - /// The location of the `1` key on the QWERTY keyboard layout. - Key1 = 0x02, - /// The location of the `2` key on the QWERTY keyboard layout. - Key2 = 0x03, - /// The location of the `3` key on the QWERTY keyboard layout. - Key3 = 0x04, - /// The location of the `4` key on the QWERTY keyboard layout. - Key4 = 0x05, - /// The location of the `5` key on the QWERTY keyboard layout. - Key5 = 0x06, - /// The location of the `6` key on the QWERTY keyboard layout. - Key6 = 0x07, - /// The location of the `7` key on the QWERTY keyboard layout. - Key7 = 0x08, - /// The location of the `8` key on the QWERTY keyboard layout. - Key8 = 0x09, - /// The location of the `9` key on the QWERTY keyboard layout. - Key9 = 0x0a, - /// The location of the `0` key on the QWERTY keyboard layout. - Key0 = 0x0b, - /// The location of the `-` key on the QWERTY keyboard layout. - Minus = 0x0c, - /// The location of the `=` key on the QWERTY keyboard layout. - Equals = 0x0d, - /// The location of the back(space) key on the QWERTY keyboard layout. - Backspace = 0x0e, - /// The location of the tabulator key on the QWERTY keyboard layout. - Tab = 0x0f, - /// The location of the `Q` key on the QWERTY keyboard layout. - Q = 0x10, - /// The location of the `W` key on the QWERTY keyboard layout. - W = 0x11, - /// The location of the `E` key on the QWERTY keyboard layout. - E = 0x12, - /// The location of the `R` key on the QWERTY keyboard layout. - R = 0x13, - /// The location of the `T` key on the QWERTY keyboard layout. - T = 0x14, - /// The location of the `Y` key on the QWERTY keyboard layout. - Y = 0x15, - /// The location of the `U` key on the QWERTY keyboard layout. - U = 0x16, - /// The location of the `I` key on the QWERTY keyboard layout. - I = 0x17, - /// The location of the `O` key on the QWERTY keyboard layout. - O = 0x18, - /// The location of the `P` key on the QWERTY keyboard layout. - P = 0x19, - /// The location of the `[` key on the QWERTY keyboard layout. - BracketLeft = 0x1a, - /// The location of the `]` key on the QWERTY keyboard layout. - BracketRight = 0x1b, - /// The location of the `\` on the QWERTY keyboard layout. - Backslash = 0x2b, - /// The location of the caps lock key on the QWERTY keyboard layout. - CapsLock = 0x3a, - /// The location of the `A` key on the QWERTY keyboard layout. - A = 0x1e, - /// The location of the `S` key on the QWERTY keyboard layout. - S = 0x1f, - /// The location of the `D` key on the QWERTY keyboard layout. - D = 0x20, - /// The location of the `F` key on the QWERTY keyboard layout. - F = 0x21, - /// The location of the `G` key on the QWERTY keyboard layout. - G = 0x22, - /// The location of the `H` key on the QWERTY keyboard layout. - H = 0x23, - /// The location of the `J` key on the QWERTY keyboard layout. - J = 0x24, - /// The location of the `K` key on the QWERTY keyboard layout. - K = 0x25, - /// The location of the `L` key on the QWERTY keyboard layout. - L = 0x26, - /// The location of the `;` key on the QWERTY keyboard layout. - SemiColon = 0x27, - /// The location of the `'` key on the QWERTY keyboard layout. - Apostrophe = 0x28, - /// A key not available on the US QWERTY layout. - /// - /// This is for example the `#` key on other layouts. - NonUs1 = 0x00, - /// The location of the Enter/Return key on the QWERTY keyboard layout. - Enter = 0x1c, - /// The location of the left Shift key on the QWERTY keyboard layout. - ShiftLeft = 0x2a, - /// The location of the `Z` key on the QWERTY keyboard layout. - Z = 0x2c, - /// The location of the `X` key on the QWERTY keyboard layout. - X = 0x2d, - /// The location of the `C` key on the QWERTY keyboard layout. - C = 0x2e, - /// The location of the `V key on the QWERTY keyboard layout. - V = 0x2f, - /// The location of the `B` key on the QWERTY keyboard layout. - B = 0x30, - /// The location of the `N` key on the QWERTY keyboard layout. - N = 0x31, - /// The location of the `M` key on the QWERTY keyboard layout. - M = 0x32, - /// The location of the `,` key on the QWERTY keyboard layout. - Comma = 0x33, - /// The location of the `.` key on the QWERTY keyboard layout. - Period = 0x34, - /// The location of the `/` key on the QWERTY keyboard layout. - Slash = 0x35, - /// The location of the right Shift key on the QWERTY keyboard layout. - ShiftRight = 0x36, - /// The location of the left Control key on the QWERTY keyboard layout. - ControlLeft = 0x1d, - /// The location of the left Alt key on the QWERTY keyboard layout. - /// Maps to left Option key on Apple keyboards. - AltLeft = 0x38, - /// The location of the Space key on the QWERTY keyboard layout. - Space = 0x39, - /// The location of the right Alt key on the QWERTY keyboard layout. - /// Maps to right Option key on Apple keyboards. - AltRight = 0xe0_e8, - /// The location of the right Control key on the QWERTY keyboard layout. - ControlRight = 0xe0_1d, - /// The location of the Insert key on the QWERTY keyboard layout. - /// Maps to the Help key on Apple keyboards. - Insert = 0xe0_52, - /// The location of the Delete key on the QWERTY keyboard layout. - Delete = 0xe0_53, - /// The location of the Home key on the QWERTY keyboard layout. - Home = 0xe0_47, - /// The location of the End key on the QWERTY keyboard layout. - End = 0xe0_4f, - /// The location of the Page Up key on the QWERTY keyboard layout. - PageUp = 0xe0_49, - /// The location of the Page Down key on the QWERTY keyboard layout. - PageDown = 0xe0_51, - /// The location of the Arrow Left key on the QWERTY keyboard layout. - Left = 0xe0_4b, - /// The location of the Arrow Up key on the QWERTY keyboard layout. - Up = 0xe0_48, - /// The location of the Arrow Down key on the QWERTY keyboard layout. - Down = 0xe0_50, - /// The location of the Arrow Right key on the QWERTY keyboard layout. - Right = 0xe0_4d, - /// The location of the Numlock key on the QWERTY keyboard layout. - /// Maps to `NumpadClear` on Apple keyboards. - Numlock = 0x45, - /// The location of the `7` key on the numpad of the QWERTY keyboard layout. - Numpad7 = 0x47, - /// The location of the `4` key on the numpad of the QWERTY keyboard layout. - Numpad4 = 0x4b, - /// The location of the `1` key on the numpad of the QWERTY keyboard layout. - Numpad1 = 0x4f, - /// The location of the `/` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadEquals` on Apple keyboards. - NumpadDivide = 0xe0_35, - /// The location of the `8` key on the numpad of the QWERTY keyboard layout. - Numpad8 = 0x48, - /// The location of the `5` key on the numpad of the QWERTY keyboard layout. - Numpad5 = 0x4c, - /// The location of the `2` key on the numpad of the QWERTY keyboard layout. - Numpad2 = 0x50, - /// The location of the `0` key on the numpad of the QWERTY keyboard layout. - Numpad0 = 0x52, - /// The location of the `*` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadDivide` on Apple keyboards. - NumpadMultiply = 0x37, - /// The location of the `9` key on the numpad of the QWERTY keyboard layout. - Numpad9 = 0x49, - /// The location of the `6` key on the numpad of the QWERTY keyboard layout. - Numpad6 = 0x4d, - /// The location of the `3` key on the numpad of the QWERTY keyboard layout. - Numpad3 = 0x51, - /// The location of the `.` key on the numpad of the QWERTY keyboard layout. - NumpadDecimal = 0x53, - /// The location of the `*` key on the numpad of the QWERTY keyboard layout. - /// Maps to `NumpadMultiply` on Apple keyboards. - NumpadSubtract = 0x4a, - /// The location of the `+` key on the numpad of the QWERTY keyboard layout. - NumpadAdd = 0x4e, - /// The location of the Enter key on the numpad of the QWERTY keyboard layout. - NumpadEnter = 0xe0_1c, - /// The location of the Escape/Esc key on the QWERTY keyboard layout. - Escape = 0x01, - /// The location of the `F1` key on the QWERTY keyboard layout. - F1 = 0x3b, - /// The location of the `F2` key on the QWERTY keyboard layout. - F2 = 0x3c, - /// The location of the `F3` key on the QWERTY keyboard layout. - F3 = 0x3d, - /// The location of the `F4` key on the QWERTY keyboard layout. - F4 = 0x3e, - /// The location of the `F5` key on the QWERTY keyboard layout. - F5 = 0x3f, - /// The location of the `F6` key on the QWERTY keyboard layout. - F6 = 0x40, - /// The location of the `F7` key on the QWERTY keyboard layout. - F7 = 0x41, - /// The location of the `F8` key on the QWERTY keyboard layout. - F8 = 0x42, - /// The location of the `F9` key on the QWERTY keyboard layout. - F9 = 0x43, - /// The location of the `F10` key on the QWERTY keyboard layout. - F10 = 0x44, - /// The location of the `F11` key on the QWERTY keyboard layout. - F11 = 0x57, - /// The location of the `F12` key on the QWERTY keyboard layout. - F12 = 0x58, - /// The location of the Snapshot / Print Screen key on the QWERTY keyboard layout. - /// Maps to the `F13` key on Apple keyboards. - Snapshot = 0xe0_37, - /// The location of the Alt+Sysrq key on the QWERTY keyboard layout. - AltSysrq = 0x54, - /// The location of the Scroll / Scroll Lock key on the QWERTY keyboard layout. - /// Maps to the `F14` key on Apple keyboards. - Scroll = 0x46, - /// The location of the Pause key on the QWERTY keyboard layout. - /// Maps to the `F15` key on Apple keyboards. - Pause = 0xe1_1d_45, - /// The location of the Ctrl+Break key on the QWERTY keyboard layout. - CtrlBreak = 0xe0_46, - /// The location of the left Windows key on the QWERTY keyboard layout. - /// Maps to the Command key on Apple keyboards. - SuperLeft = 0xe0_5b, - /// The location of the right Windows key on the QWERTY keyboard layout. - SuperRight = 0xe0_5c, - /// The location of the Menu key on the QWERTY keyboard layout. - Menu = 0xe0_5d, - /// The location of the Sleep key on the QWERTY keyboard layout. - Sleep = 0xe0_5f, - /// The location of the Power key on the QWERTY keyboard layout. - Power = 0xe0_5e, - /// The location of the Wake key on the QWERTY keyboard layout. - Wake = 0xe0_63, -} diff --git a/src/systems.rs b/src/systems.rs index 941f4808..6ac75ea3 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -7,13 +7,13 @@ use crate::{ input_streams::InputStreams, plugin::ToggleActions, Actionlike, }; -use bevy::{ecs::prelude::*, prelude::ScanCode}; +use bevy::ecs::prelude::*; use bevy::{ input::{ gamepad::{GamepadAxis, GamepadButton, Gamepads}, keyboard::KeyCode, mouse::{MouseButton, MouseMotion, MouseWheel}, - Axis, Input, + Axis, ButtonInput, }, log::warn, math::Vec2, @@ -58,18 +58,17 @@ pub fn tick_action_state( *stored_previous_instant = time.last_update(); } -/// Fetches all of the relevant [`Input`] resources to update [`ActionState`] according to the [`InputMap`]. +/// Fetches all of the relevant [`ButtonInput`] resources to update [`ActionState`] according to the [`InputMap`]. /// /// Missing resources will be ignored, and treated as if none of the corresponding inputs were pressed. #[allow(clippy::too_many_arguments)] pub fn update_action_state( - gamepad_buttons: Res>, + gamepad_buttons: Res>, gamepad_button_axes: Res>, gamepad_axes: Res>, gamepads: Res, - keycodes: Option>>, - scan_codes: Option>>, - mouse_buttons: Option>>, + keycodes: Option>>, + mouse_buttons: Option>>, mut mouse_wheel: EventReader, mut mouse_motion: EventReader, clash_strategy: Res, @@ -86,7 +85,6 @@ pub fn update_action_state( let gamepad_axes = gamepad_axes.into_inner(); let gamepads = gamepads.into_inner(); let keycodes = keycodes.map(|keycodes| keycodes.into_inner()); - let scan_codes = scan_codes.map(|scan_codes| scan_codes.into_inner()); let mouse_buttons = mouse_buttons.map(|mouse_buttons| mouse_buttons.into_inner()); let mouse_wheel: Option> = Some(mouse_wheel.read().cloned().collect()); @@ -105,14 +103,11 @@ pub fn update_action_state( // If egui wants to own inputs, don't also apply them to the game state #[cfg(feature = "egui")] - let (keycodes, scan_codes) = if maybe_egui + let keycodes = maybe_egui .iter_mut() - .any(|(_, mut ctx)| ctx.get_mut().wants_keyboard_input()) - { - (None, None) - } else { - (keycodes, scan_codes) - }; + .all(|(_, mut ctx)| !ctx.get_mut().wants_keyboard_input()) + .then_some(keycodes) + .flatten(); // `wants_pointer_input` sometimes returns `false` after clicking or holding a button over a widget, // so `is_pointer_over_area` is also needed. @@ -136,7 +131,6 @@ pub fn update_action_state( gamepad_axes, gamepads, keycodes, - scan_codes, mouse_buttons, mouse_wheel: mouse_wheel.clone(), mouse_motion: mouse_motion.clone(), diff --git a/src/user_input.rs b/src/user_input.rs index 7185625b..8777f6f8 100644 --- a/src/user_input.rs +++ b/src/user_input.rs @@ -1,13 +1,11 @@ //! Helpful abstractions over user inputs of all sorts -use bevy::input::keyboard::ScanCode; use bevy::input::{gamepad::GamepadButtonType, keyboard::KeyCode, mouse::MouseButton}; use bevy::reflect::Reflect; use bevy::utils::HashSet; use serde::{Deserialize, Serialize}; use crate::axislike::VirtualAxis; -use crate::scan_codes::QwertyScanCode; use crate::{ axislike::{AxisType, DualAxis, SingleAxis, VirtualDPad}, buttonlike::{MouseMotionDirection, MouseWheelDirection}, @@ -86,9 +84,9 @@ impl UserInput { /// use leafwing_input_manager::user_input::UserInput; /// /// let buttons = HashSet::from_iter([ControlLeft.into(), AltLeft.into()]); - /// let a: UserInput = A.into(); - /// let ctrl_a = UserInput::chord([ControlLeft, A]); - /// let ctrl_alt_a = UserInput::chord([ControlLeft, AltLeft, A]); + /// let a: UserInput = KeyA.into(); + /// let ctrl_a = UserInput::chord([ControlLeft, KeyA]); + /// let ctrl_alt_a = UserInput::chord([ControlLeft, AltLeft, KeyA]); /// /// assert_eq!(a.n_matching(&buttons), 0); /// assert_eq!(ctrl_a.n_matching(&buttons), 1); @@ -178,19 +176,7 @@ impl From for UserInput { impl From for UserInput { fn from(input: KeyCode) -> Self { - UserInput::Single(InputKind::Keyboard(input)) - } -} - -impl From for UserInput { - fn from(input: ScanCode) -> Self { - UserInput::Single(InputKind::KeyLocation(input)) - } -} - -impl From for UserInput { - fn from(input: QwertyScanCode) -> Self { - UserInput::Single(InputKind::KeyLocation(input.into())) + UserInput::Single(InputKind::PhysicalKey(input)) } } @@ -222,7 +208,7 @@ impl From for UserInput { /// /// Commonly stored in the [`UserInput`] enum. /// -/// Unfortunately we cannot use a trait object here, as the types used by `Input` +/// Unfortunately we cannot use a trait object here, as the types used by `ButtonInput` /// require traits that are not object-safe. /// /// Please contact the maintainers if you need support for another type! @@ -235,18 +221,8 @@ pub enum InputKind { SingleAxis(SingleAxis), /// Two paired axes of continuous motion DualAxis(DualAxis), - /// A logical key on the keyboard. - /// - /// The actual (physical) key that has to be pressed depends on the keyboard layout. - /// If you care about the position of the key rather than what it stands for, - /// use [`InputKind::KeyLocation`] instead. - Keyboard(KeyCode), /// The physical location of a key on the keyboard. - /// - /// The logical key which is emitted by this key depends on the keyboard layout. - /// If you care about the output of the key rather than where it is positioned, - /// use [`InputKind::Keyboard`] instead. - KeyLocation(ScanCode), + PhysicalKey(KeyCode), /// A keyboard modifier, like `Ctrl` or `Alt`, which doesn't care about which side it's on. Modifier(Modifier), /// A button on a mouse @@ -277,19 +253,7 @@ impl From for InputKind { impl From for InputKind { fn from(input: KeyCode) -> Self { - InputKind::Keyboard(input) - } -} - -impl From for InputKind { - fn from(input: ScanCode) -> Self { - InputKind::KeyLocation(input) - } -} - -impl From for InputKind { - fn from(input: QwertyScanCode) -> Self { - InputKind::KeyLocation(input.into()) + InputKind::PhysicalKey(input) } } @@ -353,10 +317,8 @@ impl Modifier { /// Obtained by calling [`UserInput::raw_inputs()`]. #[derive(Default, Debug, Clone, PartialEq)] pub struct RawInputs { - /// Logical keyboard keys. - pub keycodes: Vec, /// Physical key locations. - pub scan_codes: Vec, + pub keycodes: Vec, /// Mouse buttons pub mouse_buttons: Vec, /// Discretized mouse wheel inputs @@ -383,8 +345,7 @@ impl RawInputs { .axis_data .push((single_axis.axis_type, single_axis.value)), InputKind::GamepadButton(button) => self.gamepad_buttons.push(button), - InputKind::Keyboard(button) => self.keycodes.push(button), - InputKind::KeyLocation(scan_code) => self.scan_codes.push(scan_code), + InputKind::PhysicalKey(key_code) => self.keycodes.push(key_code), InputKind::Modifier(modifier) => { self.keycodes.extend_from_slice(&modifier.key_codes()); } @@ -540,7 +501,7 @@ mod raw_input_tests { fn keyboard_button() { use bevy::input::keyboard::KeyCode; - let button = KeyCode::A; + let button = KeyCode::KeyA; let expected = RawInputs::from_keycode(button); let raw = UserInput::from(button).raw_inputs(); assert_eq!(expected, raw); @@ -551,9 +512,9 @@ mod raw_input_tests { use crate::user_input::Modifier; use bevy::input::keyboard::KeyCode; - let input = UserInput::modified(Modifier::Control, KeyCode::S); + let input = UserInput::modified(Modifier::Control, KeyCode::KeyS); let expected = RawInputs { - keycodes: vec![KeyCode::ControlLeft, KeyCode::ControlRight, KeyCode::S], + keycodes: vec![KeyCode::ControlLeft, KeyCode::ControlRight, KeyCode::KeyS], ..Default::default() }; let raw = input.raw_inputs(); diff --git a/tests/clashes.rs b/tests/clashes.rs index 45410d4b..f98db53b 100644 --- a/tests/clashes.rs +++ b/tests/clashes.rs @@ -48,14 +48,14 @@ fn spawn_input_map(mut commands: Commands) { let mut input_map = InputMap::default(); - input_map.insert(One, Key1); - input_map.insert(Two, Key2); - input_map.insert_chord(OneAndTwo, [Key1, Key2]); - input_map.insert_chord(TwoAndThree, [Key2, Key3]); - input_map.insert_chord(OneAndTwoAndThree, [Key1, Key2, Key3]); - input_map.insert_chord(CtrlOne, [ControlLeft, Key1]); - input_map.insert_chord(AltOne, [AltLeft, Key1]); - input_map.insert_chord(CtrlAltOne, [ControlLeft, AltLeft, Key1]); + input_map.insert(One, Digit1); + input_map.insert(Two, Digit2); + input_map.insert_chord(OneAndTwo, [Digit1, Digit2]); + input_map.insert_chord(TwoAndThree, [Digit2, Digit3]); + input_map.insert_chord(OneAndTwoAndThree, [Digit1, Digit2, Digit3]); + input_map.insert_chord(CtrlOne, [ControlLeft, Digit1]); + input_map.insert_chord(AltOne, [AltLeft, Digit1]); + input_map.insert_chord(CtrlAltOne, [ControlLeft, AltLeft, Digit1]); commands.spawn(input_map); } @@ -85,7 +85,7 @@ impl ClashTestExt for App { let input_map_query = input_system_state.get(&self.world); let input_map = input_map_query.single(); - let keyboard_input = self.world.resource::>(); + let keyboard_input = self.world.resource::>(); for action in Action::variants() { if pressed_actions.contains(action) { @@ -111,8 +111,8 @@ fn two_inputs_clash_handling() { let mut app = test_app(); // Two inputs - app.send_input(Key1); - app.send_input(Key2); + app.send_input(Digit1); + app.send_input(Digit2); app.update(); app.assert_input_map_actions_eq(ClashStrategy::PressAll, [One, Two, OneAndTwo]); @@ -128,9 +128,9 @@ fn three_inputs_clash_handling() { // Three inputs app.reset_inputs(); - app.send_input(Key1); - app.send_input(Key2); - app.send_input(Key3); + app.send_input(Digit1); + app.send_input(Digit2); + app.send_input(Digit3); app.update(); app.assert_input_map_actions_eq( @@ -149,9 +149,9 @@ fn modifier_clash_handling() { // Modifier app.reset_inputs(); - app.send_input(Key1); - app.send_input(Key2); - app.send_input(Key3); + app.send_input(Digit1); + app.send_input(Digit2); + app.send_input(Digit3); app.send_input(ControlLeft); app.update(); @@ -174,7 +174,7 @@ fn multiple_modifiers_clash_handling() { // Multiple modifiers app.reset_inputs(); - app.send_input(Key1); + app.send_input(Digit1); app.send_input(ControlLeft); app.send_input(AltLeft); app.update(); @@ -192,8 +192,8 @@ fn action_order_clash_handling() { // Action order app.reset_inputs(); - app.send_input(Key3); - app.send_input(Key2); + app.send_input(Digit3); + app.send_input(Digit2); app.update(); app.assert_input_map_actions_eq(ClashStrategy::PressAll, [Two, TwoAndThree]); diff --git a/tests/integration.rs b/tests/integration.rs index 02ce4a5b..03b1196a 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -43,7 +43,7 @@ struct Player; fn spawn_player(mut commands: Commands) { commands .spawn(InputManagerBundle:: { - input_map: InputMap::::new([(Action::PayRespects, KeyCode::F)]), + input_map: InputMap::::new([(Action::PayRespects, KeyCode::KeyF)]), ..Default::default() }) .insert(Player); @@ -62,13 +62,16 @@ fn disable_input() { .add_plugins(InputManagerPlugin::::default()) .add_systems(Startup, spawn_player) .init_resource::>() - .insert_resource(InputMap::::new([(Action::PayRespects, KeyCode::F)])) + .insert_resource(InputMap::::new([( + Action::PayRespects, + KeyCode::KeyF, + )])) .init_resource::() .add_systems(Update, pay_respects) .add_systems(PreUpdate, respect_fades); // Press F to pay respects - app.send_input(KeyCode::F); + app.send_input(KeyCode::KeyF); app.update(); let respect = app.world.resource::(); assert_eq!(*respect, Respect(true)); @@ -83,7 +86,7 @@ fn disable_input() { assert_eq!(*respect, Respect(false)); // And even pressing F cannot bring it back - app.send_input(KeyCode::F); + app.send_input(KeyCode::KeyF); app.update(); let respect = app.world.resource::(); assert_eq!(*respect, Respect(false)); @@ -101,13 +104,16 @@ fn release_when_input_map_removed() { .add_plugins(InputManagerPlugin::::default()) .add_systems(Startup, spawn_player) .init_resource::>() - .insert_resource(InputMap::::new([(Action::PayRespects, KeyCode::F)])) + .insert_resource(InputMap::::new([( + Action::PayRespects, + KeyCode::KeyF, + )])) .init_resource::() .add_systems(Update, (pay_respects, remove_input_map)) .add_systems(PreUpdate, respect_fades); // Press F to pay respects - app.send_input(KeyCode::F); + app.send_input(KeyCode::KeyF); app.update(); let respect = app.world.resource::(); assert_eq!(*respect, Respect(true)); @@ -123,7 +129,7 @@ fn release_when_input_map_removed() { assert_eq!(*respect, Respect(false)); // And even pressing F cannot bring it back - app.send_input(KeyCode::F); + app.send_input(KeyCode::KeyF); app.update(); let respect = app.world.resource::(); assert_eq!(*respect, Respect(false)); @@ -143,7 +149,7 @@ fn action_state_driver() { fn setup(mut commands: Commands) { let player_entity = commands .spawn(InputManagerBundle:: { - input_map: InputMap::::new([(Action::PayRespects, KeyCode::F)]), + input_map: InputMap::::new([(Action::PayRespects, KeyCode::KeyF)]), ..Default::default() }) .insert(Player) @@ -226,7 +232,10 @@ fn duration() { .add_plugins(InputManagerPlugin::::default()) .add_systems(Startup, spawn_player) .init_resource::>() - .insert_resource(InputMap::::new([(Action::PayRespects, KeyCode::F)])) + .insert_resource(InputMap::::new([( + Action::PayRespects, + KeyCode::KeyF, + )])) .init_resource::() .add_systems(Update, hold_f_to_pay_respects); @@ -234,7 +243,7 @@ fn duration() { app.update(); // Press - app.send_input(KeyCode::F); + app.send_input(KeyCode::KeyF); // Hold std::thread::sleep(2 * RESPECTFUL_DURATION); From 20cd9c9e19f01caea4b3b6d6607e5a6221d8f56e Mon Sep 17 00:00:00 2001 From: Shute052 Date: Mon, 19 Feb 2024 23:19:50 +0800 Subject: [PATCH 2/5] RELEASES.md --- RELEASES.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 15f6e5ec..5c2db95a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -4,11 +4,11 @@ ### Breaking Changes -- both `KeyCode`-based logical keybindings and `ScanCode`-based physical keybindings are no longer supported; -- please migrate to: - - `KeyCode` is now representing physical keybindings. - - `InputKind::KeyLocation` have been removed; please use `InputKind::PhysicalKey` instead. - - `ScanCode` and `QwertyScanCode` have been removed; please use `KeyCode` instead: +- both `KeyCode`-based logical keybindings and `ScanCode`-based physical keybindings are no longer supported; please migrate to: + - `KeyCode`s are now representing physical keybindings. + - `InputKind::Keyboard` has been removed. + - `InputKind::KeyLocation` has been removed; please use `InputKind::PhysicalKey` instead. + - All `ScanCode`s and `QwertyScanCode`s have been removed; please use `KeyCode` instead: - all letter keys now follow the format `KeyCode::Key`, e.g., `ScanCode::K` is now `KeyCode::KeyK`. - all number keys over letters now follow the format `KeyCode::Digit`, e.g., `ScanCode::Key1` is now `KeyCode::Digit1`. - all arrow keys now follow the format `KeyCode::Arrow`, e.g., `ScanCode::Up` is now `KeyCode::ArrowUp`. From 01d977ce9fe59ce45d2c07a91bf0017c6ea3f14a Mon Sep 17 00:00:00 2001 From: Shute052 Date: Tue, 20 Feb 2024 06:15:42 +0800 Subject: [PATCH 3/5] Fix new test added by #473 --- src/action_state.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/action_state.rs b/src/action_state.rs index 3dfeced7..a680999d 100644 --- a/src/action_state.rs +++ b/src/action_state.rs @@ -682,9 +682,9 @@ mod tests { // Input map use bevy::prelude::KeyCode::*; let mut input_map = InputMap::default(); - input_map.insert(Action::One, Key1); - input_map.insert(Action::Two, Key2); - input_map.insert_chord(Action::OneAndTwo, [Key1, Key2]); + input_map.insert(Action::One, Digit1); + input_map.insert(Action::Two, Digit2); + input_map.insert_chord(Action::OneAndTwo, [Digit1, Digit2]); let mut app = App::new(); app.add_plugins(InputPlugin); @@ -701,7 +701,7 @@ mod tests { assert!(action_state.released(&Action::OneAndTwo)); // Pressing One - app.send_input(Key1); + app.send_input(Digit1); app.update(); let input_streams = InputStreams::from_world(&app.world, None); @@ -722,7 +722,7 @@ mod tests { assert!(action_state.released(&Action::OneAndTwo)); // Pressing Two - app.send_input(Key2); + app.send_input(Digit2); app.update(); let input_streams = InputStreams::from_world(&app.world, None); From 4d056564fc35f7b76a7580d667076a05f7bb80f4 Mon Sep 17 00:00:00 2001 From: Shute052 Date: Tue, 20 Feb 2024 10:51:40 +0800 Subject: [PATCH 4/5] Update for bevy_egui 0.25 --- Cargo.toml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5b971d57..a49dab26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,8 +42,7 @@ bevy = { version = "0.13", default-features = false, features = [ "serialize", "bevy_gilrs", ] } -# TODO(clean): Existing PR repo for update `bevy_egui` to bevy 0.13 -bevy_egui = { git = "https://github.com/Shute052/bevy_egui.git", branch = "Bevy-0.13-and-Egui-0.26", optional = true } +bevy_egui = { version = "0.25", optional = true } derive_more = { version = "0.99", default-features = false, features = [ "display", @@ -62,8 +61,7 @@ bevy = { version = "0.13", default-features = false, features = [ "bevy_core_pipeline", "x11", ] } -# TODO(clean): Existing PR repo for update `bevy_egui` to bevy 0.13 -bevy_egui = { git = "https://github.com/Shute052/bevy_egui.git", branch = "Bevy-0.13-and-Egui-0.26" } +bevy_egui = "0.25" serde_test = "1.0" criterion = "0.5" From 4b257f3d4c4f0f68a5a09dfdfab4e8328ae20a18 Mon Sep 17 00:00:00 2001 From: Shute052 Date: Tue, 20 Feb 2024 10:57:59 +0800 Subject: [PATCH 5/5] fmt --- RELEASES.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 513158c2..7cd6bb98 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -6,13 +6,13 @@ - `Modifier::Win` has been renamed to `Modifier::Super`, consistent with `KeyCode::SuperLeft` and `KeyCode::SuperRight`. - both `KeyCode`-based logical keybindings and `ScanCode`-based physical keybindings are no longer supported; please migrate to: - - `KeyCode`s are now representing physical keybindings. - - `InputKind::Keyboard` has been removed. - - `InputKind::KeyLocation` has been removed; please use `InputKind::PhysicalKey` instead. - - All `ScanCode`s and `QwertyScanCode`s have been removed; please use `KeyCode` instead: - - all letter keys now follow the format `KeyCode::Key`, e.g., `ScanCode::K` is now `KeyCode::KeyK`. - - all number keys over letters now follow the format `KeyCode::Digit`, e.g., `ScanCode::Key1` is now `KeyCode::Digit1`. - - all arrow keys now follow the format `KeyCode::Arrow`, e.g., `ScanCode::Up` is now `KeyCode::ArrowUp`. + - `KeyCode`s are now representing physical keybindings. + - `InputKind::Keyboard` has been removed. + - `InputKind::KeyLocation` has been removed; please use `InputKind::PhysicalKey` instead. + - All `ScanCode`s and `QwertyScanCode`s have been removed; please use `KeyCode` instead: + - all letter keys now follow the format `KeyCode::Key`, e.g., `ScanCode::K` is now `KeyCode::KeyK`. + - all number keys over letters now follow the format `KeyCode::Digit`, e.g., `ScanCode::Key1` is now `KeyCode::Digit1`. + - all arrow keys now follow the format `KeyCode::Arrow`, e.g., `ScanCode::Up` is now `KeyCode::ArrowUp`. ### Usability