Update keyboard.rs
docs in bevy_input
(#4517)
# Objective - Part of the splitting process of #3692. ## Solution - Document `keyboard.rs` inside of `bevy_input`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
This commit is contained in:
parent
0917c49b9b
commit
85dd291b9d
@ -1,16 +1,31 @@
|
|||||||
use crate::{ButtonState, Input};
|
use crate::{ButtonState, Input};
|
||||||
use bevy_ecs::event::EventReader;
|
use bevy_ecs::{event::EventReader, system::ResMut};
|
||||||
use bevy_ecs::system::ResMut;
|
|
||||||
|
|
||||||
/// A key input event from a keyboard device
|
/// A keyboard input event.
|
||||||
|
///
|
||||||
|
/// This event is the translated version of the `WindowEvent::KeyboardInput` from the `winit` crate.
|
||||||
|
/// It is available to the end user and can be used for game logic.
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
///
|
||||||
|
/// The event is consumed inside of the [`keyboard_input_system`](crate::keyboard::keyboard_input_system)
|
||||||
|
/// to update the [`Input<KeyCode>`](crate::Input<KeyCode>) resource.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct KeyboardInput {
|
pub struct KeyboardInput {
|
||||||
|
/// The scan code of the key.
|
||||||
pub scan_code: u32,
|
pub scan_code: u32,
|
||||||
|
/// The key code of the key.
|
||||||
pub key_code: Option<KeyCode>,
|
pub key_code: Option<KeyCode>,
|
||||||
|
/// The press state of the key.
|
||||||
pub state: ButtonState,
|
pub state: ButtonState,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the `Input<KeyCode>` resource with the latest `KeyboardInput` events
|
/// Updates the [`Input<KeyCode>`] resource with the latest [`KeyboardInput`] events.
|
||||||
|
///
|
||||||
|
/// ## Differences
|
||||||
|
///
|
||||||
|
/// The main difference between the [`KeyboardInput`] event and the [`Input<KeyCode>`] resource is that
|
||||||
|
/// the latter has convenient functions like [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`].
|
||||||
pub fn keyboard_input_system(
|
pub fn keyboard_input_system(
|
||||||
mut keyboard_input: ResMut<Input<KeyCode>>,
|
mut keyboard_input: ResMut<Input<KeyCode>>,
|
||||||
mut keyboard_input_events: EventReader<KeyboardInput>,
|
mut keyboard_input_events: EventReader<KeyboardInput>,
|
||||||
@ -31,206 +46,364 @@ pub fn keyboard_input_system(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The key code of a keyboard input.
|
/// The key code of a [`KeyboardInput`](crate::keyboard::KeyboardInput).
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
///
|
||||||
|
/// It is used as the generic `T` value of an [`Input`](crate::Input) to create a `Res<Input<KeyCode>>`.
|
||||||
|
/// The resource stores the data of the buttons of a keyboard and can be accessed inside of a system.
|
||||||
|
///
|
||||||
|
/// ## Updating
|
||||||
|
///
|
||||||
|
/// The resource is updated inside of the [`keyboard_input_system`](crate::keyboard::keyboard_input_system).
|
||||||
#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
|
||||||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
pub enum KeyCode {
|
pub enum KeyCode {
|
||||||
/// The '1' key over the letters.
|
/// The `1` key over the letters.
|
||||||
Key1,
|
Key1,
|
||||||
/// The '2' key over the letters.
|
/// The `2` key over the letters.
|
||||||
Key2,
|
Key2,
|
||||||
/// The '3' key over the letters.
|
/// The `3` key over the letters.
|
||||||
Key3,
|
Key3,
|
||||||
/// The '4' key over the letters.
|
/// The `4` key over the letters.
|
||||||
Key4,
|
Key4,
|
||||||
/// The '5' key over the letters.
|
/// The `5` key over the letters.
|
||||||
Key5,
|
Key5,
|
||||||
/// The '6' key over the letters.
|
/// The `6` key over the letters.
|
||||||
Key6,
|
Key6,
|
||||||
/// The '7' key over the letters.
|
/// The `7` key over the letters.
|
||||||
Key7,
|
Key7,
|
||||||
/// The '8' key over the letters.
|
/// The `8` key over the letters.
|
||||||
Key8,
|
Key8,
|
||||||
/// The '9' key over the letters.
|
/// The `9` key over the letters.
|
||||||
Key9,
|
Key9,
|
||||||
/// The '0' key over the 'O' and 'P' keys.
|
/// The `0` key over the letters.
|
||||||
Key0,
|
Key0,
|
||||||
|
|
||||||
|
/// The `A` key.
|
||||||
A,
|
A,
|
||||||
|
/// The `B` key.
|
||||||
B,
|
B,
|
||||||
|
/// The `C` key.
|
||||||
C,
|
C,
|
||||||
|
/// The `D` key.
|
||||||
D,
|
D,
|
||||||
|
/// The `E` key.
|
||||||
E,
|
E,
|
||||||
|
/// The `F` key.
|
||||||
F,
|
F,
|
||||||
|
/// The `G` key.
|
||||||
G,
|
G,
|
||||||
|
/// The `H` key.
|
||||||
H,
|
H,
|
||||||
|
/// The `I` key.
|
||||||
I,
|
I,
|
||||||
|
/// The `J` key.
|
||||||
J,
|
J,
|
||||||
|
/// The `K` key.
|
||||||
K,
|
K,
|
||||||
|
/// The `L` key.
|
||||||
L,
|
L,
|
||||||
|
/// The `M` key.
|
||||||
M,
|
M,
|
||||||
|
/// The `N` key.
|
||||||
N,
|
N,
|
||||||
|
/// The `O` key.
|
||||||
O,
|
O,
|
||||||
|
/// The `P` key.
|
||||||
P,
|
P,
|
||||||
|
/// The `Q` key.
|
||||||
Q,
|
Q,
|
||||||
|
/// The `R` key.
|
||||||
R,
|
R,
|
||||||
|
/// The `S` key.
|
||||||
S,
|
S,
|
||||||
|
/// The `T` key.
|
||||||
T,
|
T,
|
||||||
|
/// The `U` key.
|
||||||
U,
|
U,
|
||||||
|
/// The `V` key.
|
||||||
V,
|
V,
|
||||||
|
/// The `W` key.
|
||||||
W,
|
W,
|
||||||
|
/// The `X` key.
|
||||||
X,
|
X,
|
||||||
|
/// The `Y` key.
|
||||||
Y,
|
Y,
|
||||||
|
/// The `Z` key.
|
||||||
Z,
|
Z,
|
||||||
|
|
||||||
/// The Escape key, next to F1.
|
/// The `Escape` / `ESC` key, next to the `F1` key.
|
||||||
Escape,
|
Escape,
|
||||||
|
|
||||||
|
/// The `F1` key.
|
||||||
F1,
|
F1,
|
||||||
|
/// The `F2` key.
|
||||||
F2,
|
F2,
|
||||||
|
/// The `F3` key.
|
||||||
F3,
|
F3,
|
||||||
|
/// The `F4` key.
|
||||||
F4,
|
F4,
|
||||||
|
/// The `F5` key.
|
||||||
F5,
|
F5,
|
||||||
|
/// The `F6` key.
|
||||||
F6,
|
F6,
|
||||||
|
/// The `F7` key.
|
||||||
F7,
|
F7,
|
||||||
|
/// The `F8` key.
|
||||||
F8,
|
F8,
|
||||||
|
/// The `F9` key.
|
||||||
F9,
|
F9,
|
||||||
|
/// The `F10` key.
|
||||||
F10,
|
F10,
|
||||||
|
/// The `F11` key.
|
||||||
F11,
|
F11,
|
||||||
|
/// The `F12` key.
|
||||||
F12,
|
F12,
|
||||||
|
/// The `F13` key.
|
||||||
F13,
|
F13,
|
||||||
|
/// The `F14` key.
|
||||||
F14,
|
F14,
|
||||||
|
/// The `F15` key.
|
||||||
F15,
|
F15,
|
||||||
|
/// The `F16` key.
|
||||||
F16,
|
F16,
|
||||||
|
/// The `F17` key.
|
||||||
F17,
|
F17,
|
||||||
|
/// The `F18` key.
|
||||||
F18,
|
F18,
|
||||||
|
/// The `F19` key.
|
||||||
F19,
|
F19,
|
||||||
|
/// The `F20` key.
|
||||||
F20,
|
F20,
|
||||||
|
/// The `F21` key.
|
||||||
F21,
|
F21,
|
||||||
|
/// The `F22` key.
|
||||||
F22,
|
F22,
|
||||||
|
/// The `F23` key.
|
||||||
F23,
|
F23,
|
||||||
|
/// The `F24` key.
|
||||||
F24,
|
F24,
|
||||||
|
|
||||||
/// Print Screen/SysRq.
|
/// The `Snapshot` / `Print Screen` key.
|
||||||
Snapshot,
|
Snapshot,
|
||||||
/// Scroll Lock.
|
/// The `Scroll` / `Scroll Lock` key.
|
||||||
Scroll,
|
Scroll,
|
||||||
/// Pause/Break key, next to Scroll lock.
|
/// The `Pause` / `Break` key, next to the `Scroll` key.
|
||||||
Pause,
|
Pause,
|
||||||
|
|
||||||
/// `Insert`, next to Backspace.
|
/// The `Insert` key, next to the `Backspace` key.
|
||||||
Insert,
|
Insert,
|
||||||
|
/// The `Home` key.
|
||||||
Home,
|
Home,
|
||||||
|
/// The `Delete` key.
|
||||||
Delete,
|
Delete,
|
||||||
|
/// The `End` key.
|
||||||
End,
|
End,
|
||||||
|
/// The `PageDown` key.
|
||||||
PageDown,
|
PageDown,
|
||||||
|
/// The `PageUp` key.
|
||||||
PageUp,
|
PageUp,
|
||||||
|
|
||||||
|
/// The `Left` / `Left Arrow` key.
|
||||||
Left,
|
Left,
|
||||||
|
/// The `Up` / `Up Arrow` key.
|
||||||
Up,
|
Up,
|
||||||
|
/// The `Right` / `Right Arrow` key.
|
||||||
Right,
|
Right,
|
||||||
|
/// The `Down` / `Down Arrow` key.
|
||||||
Down,
|
Down,
|
||||||
|
|
||||||
/// The Backspace key, right over Enter.
|
/// The `Back` / `Backspace` key.
|
||||||
Back,
|
Back,
|
||||||
/// The Enter key.
|
/// The `Return` / `Enter` key.
|
||||||
Return,
|
Return,
|
||||||
/// The space bar.
|
/// The `Space` / `Spacebar` / ` ` key.
|
||||||
Space,
|
Space,
|
||||||
|
|
||||||
/// The "Compose" key on Linux.
|
/// The `Compose` key on Linux.
|
||||||
Compose,
|
Compose,
|
||||||
|
/// The `Caret` / `^` key.
|
||||||
Caret,
|
Caret,
|
||||||
|
|
||||||
|
/// The `Numlock` key.
|
||||||
Numlock,
|
Numlock,
|
||||||
|
/// The `Numpad0` / `0` key.
|
||||||
Numpad0,
|
Numpad0,
|
||||||
|
/// The `Numpad1` / `1` key.
|
||||||
Numpad1,
|
Numpad1,
|
||||||
|
/// The `Numpad2` / `2` key.
|
||||||
Numpad2,
|
Numpad2,
|
||||||
|
/// The `Numpad3` / `3` key.
|
||||||
Numpad3,
|
Numpad3,
|
||||||
|
/// The `Numpad4` / `4` key.
|
||||||
Numpad4,
|
Numpad4,
|
||||||
|
/// The `Numpad5` / `5` key.
|
||||||
Numpad5,
|
Numpad5,
|
||||||
|
/// The `Numpad6` / `6` key.
|
||||||
Numpad6,
|
Numpad6,
|
||||||
|
/// The `Numpad7` / `7` key.
|
||||||
Numpad7,
|
Numpad7,
|
||||||
|
/// The `Numpad8` / `8` key.
|
||||||
Numpad8,
|
Numpad8,
|
||||||
|
/// The `Numpad9` / `9` key.
|
||||||
Numpad9,
|
Numpad9,
|
||||||
|
|
||||||
|
/// The `AbntC1` key.
|
||||||
AbntC1,
|
AbntC1,
|
||||||
|
/// The `AbntC2` key.
|
||||||
AbntC2,
|
AbntC2,
|
||||||
|
|
||||||
|
/// The `NumpadAdd` / `+` key.
|
||||||
NumpadAdd,
|
NumpadAdd,
|
||||||
|
/// The `Apostrophe` / `'` key.
|
||||||
Apostrophe,
|
Apostrophe,
|
||||||
|
/// The `Apps` key.
|
||||||
Apps,
|
Apps,
|
||||||
|
/// The `Asterik` / `*` key.
|
||||||
Asterisk,
|
Asterisk,
|
||||||
|
/// The `Plus` / `+` key.
|
||||||
Plus,
|
Plus,
|
||||||
|
/// The `At` / `@` key.
|
||||||
At,
|
At,
|
||||||
|
/// The `Ax` key.
|
||||||
Ax,
|
Ax,
|
||||||
|
/// The `Backslash` / `\` key.
|
||||||
Backslash,
|
Backslash,
|
||||||
|
/// The `Calculator` key.
|
||||||
Calculator,
|
Calculator,
|
||||||
|
/// The `Capital` key.
|
||||||
Capital,
|
Capital,
|
||||||
|
/// The `Colon` / `:` key.
|
||||||
Colon,
|
Colon,
|
||||||
|
/// The `Comma` / `,` key.
|
||||||
Comma,
|
Comma,
|
||||||
|
/// The `Convert` key.
|
||||||
Convert,
|
Convert,
|
||||||
|
/// The `NumpadDecimal` / `.` key.
|
||||||
NumpadDecimal,
|
NumpadDecimal,
|
||||||
|
/// The `NumpadDivide` / `/` key.
|
||||||
NumpadDivide,
|
NumpadDivide,
|
||||||
|
/// The `Equals` / `=` key.
|
||||||
Equals,
|
Equals,
|
||||||
|
/// The `Grave` / `Backtick` / `` ` `` key.
|
||||||
Grave,
|
Grave,
|
||||||
|
/// The `Kana` key.
|
||||||
Kana,
|
Kana,
|
||||||
|
/// The `Kanji` key.
|
||||||
Kanji,
|
Kanji,
|
||||||
/// The left alt key. Maps to left option on Mac.
|
|
||||||
|
/// The `LAlt` / `Left Alt` key. Maps to `Left Option` on Mac.
|
||||||
LAlt,
|
LAlt,
|
||||||
|
/// The `LBracket` / `Left Bracket` key.
|
||||||
LBracket,
|
LBracket,
|
||||||
|
/// The `LControl` / `Left Control` key.
|
||||||
LControl,
|
LControl,
|
||||||
|
/// The `LShift` / `Left Shift` key.
|
||||||
LShift,
|
LShift,
|
||||||
/// The left Windows key. Maps to left Command on Mac.
|
/// The `LWin` / `Left Windows` key. Maps to `Left Command` on Mac.
|
||||||
LWin,
|
LWin,
|
||||||
|
|
||||||
|
/// The `Mail` key.
|
||||||
Mail,
|
Mail,
|
||||||
|
/// The `MediaSelect` key.
|
||||||
MediaSelect,
|
MediaSelect,
|
||||||
|
/// The `MediaStop` key.
|
||||||
MediaStop,
|
MediaStop,
|
||||||
|
/// The `Minus` / `-` key.
|
||||||
Minus,
|
Minus,
|
||||||
|
/// The `NumpadMultiply` / `*` key.
|
||||||
NumpadMultiply,
|
NumpadMultiply,
|
||||||
|
/// The `Mute` key.
|
||||||
Mute,
|
Mute,
|
||||||
|
/// The `MyComputer` key.
|
||||||
MyComputer,
|
MyComputer,
|
||||||
NavigateForward, // also called "Prior"
|
/// The `NavigateForward` / `Prior` key.
|
||||||
NavigateBackward, // also called "Next"
|
NavigateForward,
|
||||||
|
/// The `NavigateBackward` / `Next` key.
|
||||||
|
NavigateBackward,
|
||||||
|
/// The `NextTrack` key.
|
||||||
NextTrack,
|
NextTrack,
|
||||||
|
/// The `NoConvert` key.
|
||||||
NoConvert,
|
NoConvert,
|
||||||
|
/// The `NumpadComma` / `,` key.
|
||||||
NumpadComma,
|
NumpadComma,
|
||||||
|
/// The `NumpadEnter` key.
|
||||||
NumpadEnter,
|
NumpadEnter,
|
||||||
|
/// The `NumpadEquals` / `=` key.
|
||||||
NumpadEquals,
|
NumpadEquals,
|
||||||
|
/// The `Oem102` key.
|
||||||
Oem102,
|
Oem102,
|
||||||
|
/// The `Period` / `.` key.
|
||||||
Period,
|
Period,
|
||||||
|
/// The `PlayPause` key.
|
||||||
PlayPause,
|
PlayPause,
|
||||||
|
/// The `Power` key.
|
||||||
Power,
|
Power,
|
||||||
|
/// The `PrevTrack` key.
|
||||||
PrevTrack,
|
PrevTrack,
|
||||||
/// The right alt key. Maps to right option on Mac.
|
|
||||||
|
/// The `RAlt` / `Right Alt` key. Maps to `Right Option` on Mac.
|
||||||
RAlt,
|
RAlt,
|
||||||
|
/// The `RBracket` / `Right Bracket` key.
|
||||||
RBracket,
|
RBracket,
|
||||||
|
/// The `RControl` / `Right Control` key.
|
||||||
RControl,
|
RControl,
|
||||||
|
/// The `RShift` / `Right Shift` key.
|
||||||
RShift,
|
RShift,
|
||||||
/// The right Windows key. Maps to right Command on Mac.
|
/// The `RWin` / `Right Windows` key. Maps to `Right Command` on Mac.
|
||||||
RWin,
|
RWin,
|
||||||
|
|
||||||
|
/// The `Semicolon` / `;` key.
|
||||||
Semicolon,
|
Semicolon,
|
||||||
|
/// The `Slash` / `/` key.
|
||||||
Slash,
|
Slash,
|
||||||
|
/// The `Sleep` key.
|
||||||
Sleep,
|
Sleep,
|
||||||
|
/// The `Stop` key.
|
||||||
Stop,
|
Stop,
|
||||||
|
/// The `NumpadSubtract` / `-` key.
|
||||||
NumpadSubtract,
|
NumpadSubtract,
|
||||||
|
/// The `Sysrq` key.
|
||||||
Sysrq,
|
Sysrq,
|
||||||
|
/// The `Tab` / ` ` key.
|
||||||
Tab,
|
Tab,
|
||||||
|
/// The `Underline` / `_` key.
|
||||||
Underline,
|
Underline,
|
||||||
|
/// The `Unlabeled` key.
|
||||||
Unlabeled,
|
Unlabeled,
|
||||||
|
|
||||||
|
/// The `VolumeDown` key.
|
||||||
VolumeDown,
|
VolumeDown,
|
||||||
|
/// The `VolumeUp` key.
|
||||||
VolumeUp,
|
VolumeUp,
|
||||||
|
|
||||||
|
/// The `Wake` key.
|
||||||
Wake,
|
Wake,
|
||||||
|
|
||||||
|
/// The `WebBack` key.
|
||||||
WebBack,
|
WebBack,
|
||||||
|
/// The `WebFavorites` key.
|
||||||
WebFavorites,
|
WebFavorites,
|
||||||
|
/// The `WebForward` key.
|
||||||
WebForward,
|
WebForward,
|
||||||
|
/// The `WebHome` key.
|
||||||
WebHome,
|
WebHome,
|
||||||
|
/// The `WebRefresh` key.
|
||||||
WebRefresh,
|
WebRefresh,
|
||||||
|
/// The `WebSearch` key.
|
||||||
WebSearch,
|
WebSearch,
|
||||||
|
/// The `WebStop` key.
|
||||||
WebStop,
|
WebStop,
|
||||||
|
|
||||||
|
/// The `Yen` key.
|
||||||
Yen,
|
Yen,
|
||||||
|
|
||||||
|
/// The `Copy` key.
|
||||||
Copy,
|
Copy,
|
||||||
|
/// The `Paste` key.
|
||||||
Paste,
|
Paste,
|
||||||
|
/// The `Cut` key.
|
||||||
Cut,
|
Cut,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user