amethyst_input/button.rs
1use serde::{Deserialize, Serialize};
2use winit::{MouseButton, VirtualKeyCode};
3
4use super::{controller::ControllerButton, scroll_direction::ScrollDirection};
5
6/// A Button is any kind of digital input that the engine supports.
7#[derive(Eq, PartialEq, Debug, Copy, Clone, Hash, Serialize, Deserialize)]
8pub enum Button {
9 /// Virtual Keyboard keys, use this when the letter on the key matters
10 /// more than the position of the key.
11 Key(VirtualKeyCode),
12
13 /// Scan code from keyboard, use this when the position of the key matters
14 /// more than the letter on the key.
15 ScanCode(u32),
16
17 /// Mouse buttons
18 Mouse(MouseButton),
19
20 /// Mouse wheel (Do not use these with an emulated axis, instead use the MouseWheel axis.)
21 MouseWheel(ScrollDirection),
22
23 /// Controller buttons matching SDL controller model.
24 /// A tuple of sequential controller_id in order of connection
25 /// and specific type of used controller button.
26 Controller(u32, ControllerButton),
27}
28
29impl From<VirtualKeyCode> for Button {
30 fn from(keycode: VirtualKeyCode) -> Self {
31 Button::Key(keycode)
32 }
33}
34
35impl From<MouseButton> for Button {
36 fn from(mouse_button: MouseButton) -> Self {
37 Button::Mouse(mouse_button)
38 }
39}