summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/input.rs6
-rw-r--r--src/input/button_state.rs5
-rw-r--r--src/input/keyboard.rs5
-rw-r--r--src/input/keyboard/event.rs21
-rw-r--r--src/input/keyboard/key_code.rs197
-rw-r--r--src/input/mouse.rs5
-rw-r--r--src/input/mouse/button.rs7
-rw-r--r--src/input/mouse/event.rs39
8 files changed, 285 insertions, 0 deletions
diff --git a/src/input.rs b/src/input.rs
new file mode 100644
index 00000000..282d5c00
--- /dev/null
+++ b/src/input.rs
@@ -0,0 +1,6 @@
+pub mod keyboard;
+pub mod mouse;
+
+mod button_state;
+
+pub use button_state::ButtonState;
diff --git a/src/input/button_state.rs b/src/input/button_state.rs
new file mode 100644
index 00000000..e8845cc7
--- /dev/null
+++ b/src/input/button_state.rs
@@ -0,0 +1,5 @@
+#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
+pub enum ButtonState {
+ Pressed,
+ Released,
+}
diff --git a/src/input/keyboard.rs b/src/input/keyboard.rs
new file mode 100644
index 00000000..2b0188ff
--- /dev/null
+++ b/src/input/keyboard.rs
@@ -0,0 +1,5 @@
+mod event;
+mod key_code;
+
+pub use event::Event;
+pub use key_code::KeyCode;
diff --git a/src/input/keyboard/event.rs b/src/input/keyboard/event.rs
new file mode 100644
index 00000000..3804c42d
--- /dev/null
+++ b/src/input/keyboard/event.rs
@@ -0,0 +1,21 @@
+use super::KeyCode;
+use crate::input::ButtonState;
+
+#[derive(Debug, Clone, Copy, PartialEq)]
+/// A keyboard event.
+pub enum Event {
+ /// A keyboard key was pressed or released.
+ Input {
+ /// The state of the key
+ state: ButtonState,
+
+ /// The key identifier
+ key_code: KeyCode,
+ },
+
+ /// Text was entered.
+ TextEntered {
+ /// The character entered
+ character: char,
+ },
+}
diff --git a/src/input/keyboard/key_code.rs b/src/input/keyboard/key_code.rs
new file mode 100644
index 00000000..5cf9301f
--- /dev/null
+++ b/src/input/keyboard/key_code.rs
@@ -0,0 +1,197 @@
+/// The symbolic name of a keyboard key
+#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
+#[repr(u32)]
+pub enum KeyCode {
+ /// The '1' key over the letters.
+ Key1,
+ /// The '2' key over the letters.
+ Key2,
+ /// The '3' key over the letters.
+ Key3,
+ /// The '4' key over the letters.
+ Key4,
+ /// The '5' key over the letters.
+ Key5,
+ /// The '6' key over the letters.
+ Key6,
+ /// The '7' key over the letters.
+ Key7,
+ /// The '8' key over the letters.
+ Key8,
+ /// The '9' key over the letters.
+ Key9,
+ /// The '0' key over the 'O' and 'P' keys.
+ Key0,
+
+ A,
+ B,
+ C,
+ D,
+ E,
+ F,
+ G,
+ H,
+ I,
+ J,
+ K,
+ L,
+ M,
+ N,
+ O,
+ P,
+ Q,
+ R,
+ S,
+ T,
+ U,
+ V,
+ W,
+ X,
+ Y,
+ Z,
+
+ /// The Escape key, next to F1.
+ Escape,
+
+ F1,
+ F2,
+ F3,
+ F4,
+ F5,
+ F6,
+ F7,
+ F8,
+ F9,
+ F10,
+ F11,
+ F12,
+ F13,
+ F14,
+ F15,
+ F16,
+ F17,
+ F18,
+ F19,
+ F20,
+ F21,
+ F22,
+ F23,
+ F24,
+
+ /// Print Screen/SysRq.
+ Snapshot,
+ /// Scroll Lock.
+ Scroll,
+ /// Pause/Break key, next to Scroll lock.
+ Pause,
+
+ /// `Insert`, next to Backspace.
+ Insert,
+ Home,
+ Delete,
+ End,
+ PageDown,
+ PageUp,
+
+ Left,
+ Up,
+ Right,
+ Down,
+
+ /// The Backspace key, right over Enter.
+ // TODO: rename
+ Back,
+ /// The Enter key.
+ Return,
+ /// The space bar.
+ Space,
+
+ /// The "Compose" key on Linux.
+ Compose,
+
+ Caret,
+
+ Numlock,
+ Numpad0,
+ Numpad1,
+ Numpad2,
+ Numpad3,
+ Numpad4,
+ Numpad5,
+ Numpad6,
+ Numpad7,
+ Numpad8,
+ Numpad9,
+
+ AbntC1,
+ AbntC2,
+ Add,
+ Apostrophe,
+ Apps,
+ At,
+ Ax,
+ Backslash,
+ Calculator,
+ Capital,
+ Colon,
+ Comma,
+ Convert,
+ Decimal,
+ Divide,
+ Equals,
+ Grave,
+ Kana,
+ Kanji,
+ LAlt,
+ LBracket,
+ LControl,
+ LShift,
+ LWin,
+ Mail,
+ MediaSelect,
+ MediaStop,
+ Minus,
+ Multiply,
+ Mute,
+ MyComputer,
+ NavigateForward, // also called "Prior"
+ NavigateBackward, // also called "Next"
+ NextTrack,
+ NoConvert,
+ NumpadComma,
+ NumpadEnter,
+ NumpadEquals,
+ OEM102,
+ Period,
+ PlayPause,
+ Power,
+ PrevTrack,
+ RAlt,
+ RBracket,
+ RControl,
+ RShift,
+ RWin,
+ Semicolon,
+ Slash,
+ Sleep,
+ Stop,
+ Subtract,
+ Sysrq,
+ Tab,
+ Underline,
+ Unlabeled,
+ VolumeDown,
+ VolumeUp,
+ Wake,
+ WebBack,
+ WebFavorites,
+ WebForward,
+ WebHome,
+ WebRefresh,
+ WebSearch,
+ WebStop,
+ Yen,
+ Copy,
+ Paste,
+ Cut,
+}
diff --git a/src/input/mouse.rs b/src/input/mouse.rs
new file mode 100644
index 00000000..49a62961
--- /dev/null
+++ b/src/input/mouse.rs
@@ -0,0 +1,5 @@
+mod button;
+mod event;
+
+pub use button::Button;
+pub use event::Event;
diff --git a/src/input/mouse/button.rs b/src/input/mouse/button.rs
new file mode 100644
index 00000000..c51bedfc
--- /dev/null
+++ b/src/input/mouse/button.rs
@@ -0,0 +1,7 @@
+#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
+pub enum Button {
+ Left,
+ Right,
+ Middle,
+ Other(u8),
+}
diff --git a/src/input/mouse/event.rs b/src/input/mouse/event.rs
new file mode 100644
index 00000000..1f7a1547
--- /dev/null
+++ b/src/input/mouse/event.rs
@@ -0,0 +1,39 @@
+use super::Button;
+use crate::input::ButtonState;
+
+/// A mouse event.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum Event {
+ /// The mouse cursor entered the window.
+ CursorEntered,
+
+ /// The mouse cursor left the window.
+ CursorLeft,
+
+ /// The mouse cursor was moved
+ CursorMoved {
+ /// The X coordinate of the mouse position
+ x: f32,
+
+ /// The Y coordinate of the mouse position
+ y: f32,
+ },
+
+ /// A mouse button was pressed or released.
+ Input {
+ /// The state of the button
+ state: ButtonState,
+
+ /// The button identifier
+ button: Button,
+ },
+
+ /// The mouse wheel was scrolled.
+ WheelScrolled {
+ /// The number of horizontal lines scrolled
+ delta_x: f32,
+
+ /// The number of vertical lines scrolled
+ delta_y: f32,
+ },
+}