# core/inputmanager (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/inputmanager/

Input manager.
- Key names are in KeyboardEvent.code form like the original. ("KeyA", "ArrowLeft", "Space" ...)
  winit's KeyCode names follow the same W3C convention, so they are converted to strings as is. Only for the Windows key (Command key), winit calls it SuperLeft, SuperRight
  and calls the old W3C Super key Meta, so the desktop platform puts in MetaLeft, MetaRight, Super instead.
- The constant names of KeyCode are the original KeyCode key names converted to Rust constant form. (DIGIT0 for things like "0" that cannot be a name)
  LEFT, UP, RIGHT, DOWN, which were not in the original, are kept with the same values as the ARROWLEFT family.
- The mouse button (or first finger) is handled as touch. (the original merges mouse and touch into one) Like the original, initially any button is touch,
  and with set_touch_from_left_button_only(true) only the left button is touch. Whether to block the canvas right-click menu (set_context_menu_prevented, initially true) blocks the browser context menu on the web.
  Desktop windows have no browser context menu, so the result is the same as blocking it in Chrome.
- It also holds the pressed state of the three mouse buttons (left, middle, right), the list of touching fingers, whether the last input was a finger, and whether the wheel was rolled with Ctrl.
  Places that use input beyond the single button touch, like camera gestures (CameraGestures), read them. The platform fills them in. (vanilla.js read canvas DOM events directly)
- Gamepads, like the original, are polled in tick by the GamepadManager that InputManager holds. (core/gamepadmanager.rs)
- Text input (committed text, IME composition, editing keys) is gathered in the TextInput queue. Input fields take it from there. (core/textinput.rs, a layer not in the original)
- This frame's presses and releases of keys and mouse buttons are seen by accumulating events that came after the end of the last frame, like the original. A press and release between frames is also caught.
- Fingers, like the original, receive touch (begin_touch_point), move and release and are given a phase (TouchPhase), and a lifted finger stays in get_ended_touch_points for one frame.
- It holds the last used device (InputDevice) and pad kind, the keys to block (set_prevented_keys), whether typing in a text field (is_typing_in_text_field), and input actions (InputActions).
  The keys to block prevent browser default actions on the web (such as Tab moving focus, Space and arrows scrolling, F5 refreshing). Desktop windows have no such default actions, so the result is the same as blocking them.
  For text fields it looks at the engine input field (the active field of TextInput) and, on the web, the document focus (text input, textarea, contenteditable, select).

Example: Reading the keys, mouse buttons and fingers the platform put in, and passing the end of the frame

```rust
use vanilla::{InputManager, KeyCode, MouseButton, TouchPhase, Vector2};

let mut input_manager = InputManager::new();
input_manager.push_key(KeyCode::SPACE);
input_manager.set_mouse_button_down(MouseButton::Left, true);
input_manager.begin_touch_point(1, Vector2::create(10.0, 20.0), Vector2::create(20.0, 40.0));
assert!(input_manager.is_key_just_pressed(KeyCode::SPACE));
assert!(input_manager.is_mouse_button_just_pressed(MouseButton::Left));
assert_eq!(input_manager.get_touch_points()[0].phase, TouchPhase::Began);

input_manager.update_frame_snapshot();
assert!(input_manager.is_key_pressed(KeyCode::SPACE));
assert!(!input_manager.is_key_just_pressed(KeyCode::SPACE));
assert!(input_manager.is_mouse_button_down(MouseButton::Left));
assert_eq!(input_manager.get_touch_points()[0].phase, TouchPhase::Stationary);
```

## KeyCode (struct)

Key name. (the original KeyCode)
- The value is a KeyboardEvent.code string. Keys not among the constants use their name string (like "ShiftRight", "ControlRight") as is.

Example: Reading constant values and keys

```rust
use vanilla::{InputManager, KeyCode};

assert_eq!(KeyCode::A, "KeyA");
assert_eq!(KeyCode::LEFT, KeyCode::ARROWLEFT);
let mut input_manager = InputManager::new();
input_manager.push_key(KeyCode::ENTER);
assert!(input_manager.is_key_pressed("Enter"));
assert!(!input_manager.is_key_pressed(KeyCode::NUMPAD_ENTER));
```

- `pub const A: &'static str = "KeyA"` (static, since 0.3.2): A key.
  - returns &'static str
- `pub const B: &'static str = "KeyB"` (static, since 0.3.2): B key.
  - returns &'static str
- `pub const C: &'static str = "KeyC"` (static, since 0.3.2): C key.
  - returns &'static str
- `pub const D: &'static str = "KeyD"` (static, since 0.3.2): D key.
  - returns &'static str
- `pub const E: &'static str = "KeyE"` (static, since 0.3.2): E key.
  - returns &'static str
- `pub const F: &'static str = "KeyF"` (static, since 0.3.2): F key.
  - returns &'static str
- `pub const G: &'static str = "KeyG"` (static, since 0.3.2): G key.
  - returns &'static str
- `pub const H: &'static str = "KeyH"` (static, since 0.3.2): H key.
  - returns &'static str
- `pub const I: &'static str = "KeyI"` (static, since 0.3.2): I key.
  - returns &'static str
- `pub const J: &'static str = "KeyJ"` (static, since 0.3.2): J key.
  - returns &'static str
- `pub const K: &'static str = "KeyK"` (static, since 0.3.2): K key.
  - returns &'static str
- `pub const L: &'static str = "KeyL"` (static, since 0.3.2): L key.
  - returns &'static str
- `pub const M: &'static str = "KeyM"` (static, since 0.3.2): M key.
  - returns &'static str
- `pub const N: &'static str = "KeyN"` (static, since 0.3.2): N key.
  - returns &'static str
- `pub const O: &'static str = "KeyO"` (static, since 0.3.2): O key.
  - returns &'static str
- `pub const P: &'static str = "KeyP"` (static, since 0.3.2): P key.
  - returns &'static str
- `pub const Q: &'static str = "KeyQ"` (static, since 0.3.2): Q key.
  - returns &'static str
- `pub const R: &'static str = "KeyR"` (static, since 0.3.2): R key.
  - returns &'static str
- `pub const S: &'static str = "KeyS"` (static, since 0.3.2): S key.
  - returns &'static str
- `pub const T: &'static str = "KeyT"` (static, since 0.3.2): T key.
  - returns &'static str
- `pub const U: &'static str = "KeyU"` (static, since 0.3.2): U key.
  - returns &'static str
- `pub const V: &'static str = "KeyV"` (static, since 0.3.2): V key.
  - returns &'static str
- `pub const W: &'static str = "KeyW"` (static, since 0.3.2): W key.
  - returns &'static str
- `pub const X: &'static str = "KeyX"` (static, since 0.3.2): X key.
  - returns &'static str
- `pub const Y: &'static str = "KeyY"` (static, since 0.3.2): Y key.
  - returns &'static str
- `pub const Z: &'static str = "KeyZ"` (static, since 0.3.2): Z key.
  - returns &'static str
- `pub const DIGIT0: &'static str = "Digit0"` (static, since 0.3.2): Digit 0 key. (top row of the main keyboard, the numpad one is NUMPAD0)
  - returns &'static str
- `pub const DIGIT1: &'static str = "Digit1"` (static, since 0.3.2): Digit 1 key. (top row of the main keyboard, the numpad one is NUMPAD1)
  - returns &'static str
- `pub const DIGIT2: &'static str = "Digit2"` (static, since 0.3.2): Digit 2 key. (top row of the main keyboard, the numpad one is NUMPAD2)
  - returns &'static str
- `pub const DIGIT3: &'static str = "Digit3"` (static, since 0.3.2): Digit 3 key. (top row of the main keyboard, the numpad one is NUMPAD3)
  - returns &'static str
- `pub const DIGIT4: &'static str = "Digit4"` (static, since 0.3.2): Digit 4 key. (top row of the main keyboard, the numpad one is NUMPAD4)
  - returns &'static str
- `pub const DIGIT5: &'static str = "Digit5"` (static, since 0.3.2): Digit 5 key. (top row of the main keyboard, the numpad one is NUMPAD5)
  - returns &'static str
- `pub const DIGIT6: &'static str = "Digit6"` (static, since 0.3.2): Digit 6 key. (top row of the main keyboard, the numpad one is NUMPAD6)
  - returns &'static str
- `pub const DIGIT7: &'static str = "Digit7"` (static, since 0.3.2): Digit 7 key. (top row of the main keyboard, the numpad one is NUMPAD7)
  - returns &'static str
- `pub const DIGIT8: &'static str = "Digit8"` (static, since 0.3.2): Digit 8 key. (top row of the main keyboard, the numpad one is NUMPAD8)
  - returns &'static str
- `pub const DIGIT9: &'static str = "Digit9"` (static, since 0.3.2): Digit 9 key. (top row of the main keyboard, the numpad one is NUMPAD9)
  - returns &'static str
- `pub const BACKSPACE: &'static str = "Backspace"` (static, since 0.3.2): Backspace key.
  - returns &'static str
- `pub const TAB: &'static str = "Tab"` (static, since 0.3.2): Tab key.
  - returns &'static str
- `pub const ENTER: &'static str = "Enter"` (static, since 0.3.2): Enter key. (main keyboard, the numpad Enter is NUMPAD_ENTER)
  - returns &'static str
- `pub const SHIFT: &'static str = "ShiftLeft"` (static, since 0.3.2): Left Shift key. (the right one is "ShiftRight")
  - returns &'static str
- `pub const CTRL: &'static str = "ControlLeft"` (static, since 0.3.2): Left Control key. (the right one is "ControlRight")
  - returns &'static str
- `pub const ALT: &'static str = "AltLeft"` (static, since 0.3.2): Left Alt key. (the right one is "AltRight")
  - returns &'static str
- `pub const CAPSLOCK: &'static str = "CapsLock"` (static, since 0.3.2): Caps Lock key.
  - returns &'static str
- `pub const ESCAPE: &'static str = "Escape"` (static, since 0.3.2): Escape key.
  - returns &'static str
- `pub const SPACE: &'static str = "Space"` (static, since 0.3.2): Space bar.
  - returns &'static str
- `pub const PAGEUP: &'static str = "PageUp"` (static, since 0.3.2): Page Up key.
  - returns &'static str
- `pub const PAGEDOWN: &'static str = "PageDown"` (static, since 0.3.2): Page Down key.
  - returns &'static str
- `pub const END: &'static str = "End"` (static, since 0.3.2): End key.
  - returns &'static str
- `pub const HOME: &'static str = "Home"` (static, since 0.3.2): Home key.
  - returns &'static str
- `pub const LEFT: &'static str = "ArrowLeft"` (static, since 0.3.2): Left arrow key. (same value as ARROWLEFT)
  - returns &'static str
- `pub const UP: &'static str = "ArrowUp"` (static, since 0.3.2): Up arrow key. (same value as ARROWUP)
  - returns &'static str
- `pub const RIGHT: &'static str = "ArrowRight"` (static, since 0.3.2): Right arrow key. (same value as ARROWRIGHT)
  - returns &'static str
- `pub const DOWN: &'static str = "ArrowDown"` (static, since 0.3.2): Down arrow key. (same value as ARROWDOWN)
  - returns &'static str
- `pub const INSERT: &'static str = "Insert"` (static, since 0.3.2): Insert key.
  - returns &'static str
- `pub const DELETE: &'static str = "Delete"` (static, since 0.3.2): Delete key.
  - returns &'static str
- `pub const F1: &'static str = "F1"` (static, since 0.3.2): F1 key.
  - returns &'static str
- `pub const F2: &'static str = "F2"` (static, since 0.3.2): F2 key.
  - returns &'static str
- `pub const F3: &'static str = "F3"` (static, since 0.3.2): F3 key.
  - returns &'static str
- `pub const F4: &'static str = "F4"` (static, since 0.3.2): F4 key.
  - returns &'static str
- `pub const F5: &'static str = "F5"` (static, since 0.3.2): F5 key.
  - returns &'static str
- `pub const F6: &'static str = "F6"` (static, since 0.3.2): F6 key.
  - returns &'static str
- `pub const F7: &'static str = "F7"` (static, since 0.3.2): F7 key.
  - returns &'static str
- `pub const F8: &'static str = "F8"` (static, since 0.3.2): F8 key.
  - returns &'static str
- `pub const F9: &'static str = "F9"` (static, since 0.3.2): F9 key.
  - returns &'static str
- `pub const F10: &'static str = "F10"` (static, since 0.3.2): F10 key.
  - returns &'static str
- `pub const F11: &'static str = "F11"` (static, since 0.3.2): F11 key.
  - returns &'static str
- `pub const F12: &'static str = "F12"` (static, since 0.3.2): F12 key.
  - returns &'static str
- `pub const ARROWLEFT: &'static str = "ArrowLeft"` (static, since 0.4.0): Left arrow key.
  - returns &'static str
- `pub const ARROWUP: &'static str = "ArrowUp"` (static, since 0.4.0): Up arrow key.
  - returns &'static str
- `pub const ARROWRIGHT: &'static str = "ArrowRight"` (static, since 0.4.0): Right arrow key.
  - returns &'static str
- `pub const ARROWDOWN: &'static str = "ArrowDown"` (static, since 0.4.0): Down arrow key.
  - returns &'static str
- `pub const SCROLLLOCK: &'static str = "ScrollLock"` (static, since 0.4.0): Scroll Lock key.
  - returns &'static str
- `pub const SEMICOLON: &'static str = "Semicolon"` (static, since 0.4.0): Semicolon key. (`;`)
  - returns &'static str
- `pub const EQUAL: &'static str = "Equal"` (static, since 0.4.0): Equal key. (`=`)
  - returns &'static str
- `pub const COMMA: &'static str = "Comma"` (static, since 0.4.0): Comma key. (`,`)
  - returns &'static str
- `pub const MINUS: &'static str = "Minus"` (static, since 0.4.0): Minus key. (`-`)
  - returns &'static str
- `pub const PERIOD: &'static str = "Period"` (static, since 0.4.0): Period key. (`.`)
  - returns &'static str
- `pub const SLASH: &'static str = "Slash"` (static, since 0.4.0): Slash key. (`/`)
  - returns &'static str
- `pub const BACKQUOTE: &'static str = "Backquote"` (static, since 0.4.0): Backquote key. (the key left of digit 1)
  - returns &'static str
- `pub const BRACKETLEFT: &'static str = "BracketLeft"` (static, since 0.4.0): Left bracket key. (`[`)
  - returns &'static str
- `pub const BACKSLASH: &'static str = "Backslash"` (static, since 0.4.0): Backslash key. (`\`)
  - returns &'static str
- `pub const BRACKETRIGHT: &'static str = "BracketRight"` (static, since 0.4.0): Right bracket key. (`]`)
  - returns &'static str
- `pub const QUOTE: &'static str = "Quote"` (static, since 0.4.0): Quote key. (`'`)
  - returns &'static str
- `pub const META: &'static str = "MetaLeft"` (static, since 0.4.0): Left Meta key. (the Windows key, the Command key on Mac)
  - returns &'static str
- `pub const COMMAND: &'static str = "MetaLeft"` (static, since 0.4.0): Left Command key on Mac. (same value as META)
  - returns &'static str
- `pub const PAUSE: &'static str = "Pause"` (static, since 0.4.0): Pause key.
  - returns &'static str
- `pub const AUDIOVOLUMEUP: &'static str = "AudioVolumeUp"` (static, since 0.4.0): Volume up key.
  - returns &'static str
- `pub const AUDIOVOLUMEDOWN: &'static str = "AudioVolumeDown"` (static, since 0.4.0): Volume down key.
  - returns &'static str
- `pub const AUDIOMUTE: &'static str = "AudioVolumeMute"` (static, since 0.4.0): Mute. (AudioVolumeMute, its name in the W3C code table)
  - returns &'static str
- `pub const AUDIOPLAY: &'static str = "MediaPlayPause"` (static, since 0.4.0): Play/pause. (MediaPlayPause, its name in the W3C code table, the table has no MediaPlay)
  - returns &'static str
- `pub const AUDIOSTOP: &'static str = "MediaStop"` (static, since 0.4.0): Media stop key.
  - returns &'static str
- `pub const AUDIOPREV: &'static str = "MediaTrackPrevious"` (static, since 0.4.0): Previous track key.
  - returns &'static str
- `pub const AUDIONEXT: &'static str = "MediaTrackNext"` (static, since 0.4.0): Next track key.
  - returns &'static str
- `pub const NUM_LOCK: &'static str = "NumLock"` (static, since 0.4.0): Num Lock key.
  - returns &'static str
- `pub const NUMPAD_DIVIDE: &'static str = "NumpadDivide"` (static, since 0.4.0): Numpad divide.
  - returns &'static str
- `pub const NUMPAD_MULTIPLY: &'static str = "NumpadMultiply"` (static, since 0.4.0): Numpad multiply.
  - returns &'static str
- `pub const NUMPAD_SUBTRACT: &'static str = "NumpadSubtract"` (static, since 0.4.0): Numpad subtract.
  - returns &'static str
- `pub const NUMPAD_DECIMAL: &'static str = "NumpadDecimal"` (static, since 0.4.0): Numpad decimal point.
  - returns &'static str
- `pub const NUMPAD_ADD: &'static str = "NumpadAdd"` (static, since 0.4.0): Numpad add.
  - returns &'static str
- `pub const NUMPAD_ENTER: &'static str = "NumpadEnter"` (static, since 0.4.0): Numpad Enter.
  - returns &'static str
- `pub const NUMPAD0: &'static str = "Numpad0"` (static, since 0.4.0): Numpad 0.
  - returns &'static str
- `pub const NUMPAD1: &'static str = "Numpad1"` (static, since 0.4.0): Numpad 1.
  - returns &'static str
- `pub const NUMPAD2: &'static str = "Numpad2"` (static, since 0.4.0): Numpad 2.
  - returns &'static str
- `pub const NUMPAD3: &'static str = "Numpad3"` (static, since 0.4.0): Numpad 3.
  - returns &'static str
- `pub const NUMPAD4: &'static str = "Numpad4"` (static, since 0.4.0): Numpad 4.
  - returns &'static str
- `pub const NUMPAD5: &'static str = "Numpad5"` (static, since 0.4.0): Numpad 5.
  - returns &'static str
- `pub const NUMPAD6: &'static str = "Numpad6"` (static, since 0.4.0): Numpad 6.
  - returns &'static str
- `pub const NUMPAD7: &'static str = "Numpad7"` (static, since 0.4.0): Numpad 7.
  - returns &'static str
- `pub const NUMPAD8: &'static str = "Numpad8"` (static, since 0.4.0): Numpad 8.
  - returns &'static str
- `pub const NUMPAD9: &'static str = "Numpad9"` (static, since 0.4.0): Numpad 9.
  - returns &'static str

## TouchPoint (struct) (Clone, Copy, PartialEq, Debug)

One touching finger. (the platform's finger number, phase, canvas logical coordinates and view coordinates)

Example: Touching with two fingers and lifting one

```rust
use vanilla::{InputManager, TouchPhase, Vector2};

let mut input_manager = InputManager::new();
input_manager.begin_touch_point(3, Vector2::create(10.0, 10.0), Vector2::create(20.0, 20.0));
input_manager.begin_touch_point(4, Vector2::create(50.0, 10.0), Vector2::create(100.0, 20.0));
input_manager.end_touch_point(3, Vector2::create(12.0, 10.0), Vector2::create(24.0, 20.0), false);
let touch_point = input_manager.get_touch_points()[0];
assert_eq!(touch_point.identifier, 4);
assert_eq!(touch_point.view_position, Vector2::create(100.0, 20.0));
let ended_touch_point = input_manager.get_ended_touch_points()[0];
assert_eq!(ended_touch_point.phase, TouchPhase::Ended);
assert_eq!(ended_touch_point.canvas_native_position, Vector2::create(12.0, 10.0));
```

- `pub identifier: i64` (field, since 0.4.0): The platform's finger number. (stays the same while touching)
  - returns i64
- `pub phase: TouchPhase` (field, since 0.4.0): Phase.
  - returns TouchPhase
- `pub canvas_native_position: Vector2` (field, since 0.4.0): Position in logical coordinates inside the window (canvas). (0 at the top left of the canvas, logical pixels)
  - returns Vector2
- `pub view_position: Vector2` (field, since 0.4.0): Position in view coordinates. (converted with ViewManager.canvas_position_to_view_position)
  - returns Vector2

## InputManager (struct) (Default)

Input manager. (the original InputManager)
- The engine holds one and the platform puts in key, mouse, finger and wheel events. Scenes read it with engine.get_input_manager().
- This frame's presses and releases, touch Pressed / Released / Cancelled, and wheel deltas are cleared by the engine at the end of the frame.

Example: Reading keys, mouse and wheel in a scene

```rust
use vanilla::{Engine, EngineConfiguration, KeyCode, MouseButton, Scene, SceneBase};

struct MainScene {
	scene_base: SceneBase,
}

impl Scene for MainScene {
	fn get_scene_base(&self) -> &SceneBase {
		&self.scene_base
	}

	fn get_scene_base_mut(&mut self) -> &mut SceneBase {
		&mut self.scene_base
	}

	fn load(&mut self, engine: &Engine) {
		let mut input_manager = engine.get_input_manager_mut();
		input_manager.set_prevented_keys(&[KeyCode::TAB, KeyCode::SPACE]);
		input_manager.set_touch_from_left_button_only(true);
	}

	fn tick(&mut self, time_delta: f64) {
		let engine = Engine::get_engine().unwrap();
		self.scene_base.tick(time_delta);
		let input_manager = engine.get_input_manager();
		if input_manager.is_key_just_pressed(KeyCode::SPACE) {
			println!("jump");
		}
		if input_manager.is_mouse_button_down(MouseButton::Right) {
			println!("{:?}", input_manager.get_view_input_position());
		}
		if input_manager.has_wheel_delta() {
			println!("{}", input_manager.get_wheel_delta_y());
		}
	}
}

let engine_configuration = EngineConfiguration::new();
let engine = Engine::new(engine_configuration);
let main_scene = MainScene {
	scene_base: SceneBase::new(),
};
engine.run(Box::new(main_scene)).unwrap();
```

- `pub fn new() -> InputManager` (constructor, since 0.3.2): Constructor.
  - Blocks the right-click menu and passes any mouse button as touch. On devices whose main input is fingers, the last device starts as Touch.
  - returns InputManager: Input manager with no keys pressed.
- `pub fn tick(&mut self, time_delta: f64)` (method, since 0.3.2): Periodic update. (polls gamepads, sets the last device to gamepad if a pad was used, updates input actions)
  - The engine calls it at the start of a frame. On the first call it opens the gamepad input source (gilrs on desktop).
  - `time_delta` f64: Seconds elapsed since the last frame. (used for the repeat timing of input actions)
- `pub fn clear(&mut self)` (method, since 0.3.2): Clears all input state. (when the window loses focus)
- `pub fn add_wheel_delta(&mut self, delta_x: f64, delta_y: f64)` (method, since 0.3.2): Accumulates wheel deltas.
  - The platform calls it for every wheel event, and the engine clears it with clear_wheel_delta at the end of the frame.
  - `delta_x` f64: Horizontal delta. (pixels, same direction as the browser WheelEvent.deltaX)
  - `delta_y` f64: Vertical delta. (pixels, same direction as the browser WheelEvent.deltaY, positive when scrolling the content down)

  Example: Reading two wheel rolls in one frame together

  ```rust
  use vanilla::InputManager;
  
  let mut input_manager = InputManager::new();
  input_manager.add_wheel_delta(0.0, 40.0);
  input_manager.add_wheel_delta(0.0, 40.0);
  assert!(input_manager.has_wheel_delta());
  assert_eq!(input_manager.get_wheel_delta_y(), 80.0);
  input_manager.clear_wheel_delta();
  assert!(!input_manager.has_wheel_delta());
  ```

- `pub fn get_wheel_delta_x(&self) -> f64` (method, since 0.3.2): Horizontal wheel delta this frame.
  - returns f64: Horizontal delta accumulated this frame. (pixels, positive when scrolling right)
- `pub fn get_wheel_delta_y(&self) -> f64` (method, since 0.3.2): Vertical wheel delta this frame.
  - returns f64: Vertical delta accumulated this frame. (pixels, positive when scrolling the content down)
- `pub fn has_wheel_delta(&self) -> bool` (method, since 0.3.2): Whether the wheel was rolled this frame.
  - returns bool: true if the horizontal or vertical delta is not 0.
- `pub fn clear_wheel_delta(&mut self)` (method, since 0.3.2): Clears the wheel deltas. (called by the engine at the end of the frame)
- `pub fn push_key(&mut self, key: &str)` (method, since 0.3.2): Records a key press.
  - If already pressed (key repeat), it is not counted as a press this frame.
  - `key` &str: Key name. (KeyboardEvent.code, a KeyCode value)
- `pub fn pop_key(&mut self, key: &str)` (method, since 0.3.2): Records a key release.
  - Does nothing if the key was not pressed.
  - `key` &str: Key name. (KeyboardEvent.code, a KeyCode value)
- `pub fn is_key_pressed(&self, key: &str) -> bool` (method, since 0.3.2): Whether a key is pressed.
  - `key` &str: Key name. (KeyboardEvent.code, a KeyCode value)
  - returns bool: true if held.
- `pub fn is_key_just_pressed(&self, key: &str) -> bool` (method, since 0.3.2): Whether pressed this frame. (events since the end of the last frame, also true for a key pressed and released between frames, in which case is_key_pressed is false)
  - `key` &str: Key name. (KeyboardEvent.code, a KeyCode value)
  - returns bool: true if newly pressed since the end of the last frame. (key repeat is not counted)

  Example: A key pressed and released between frames

  ```rust
  use vanilla::{InputManager, KeyCode};
  
  let mut input_manager = InputManager::new();
  input_manager.push_key(KeyCode::Z);
  input_manager.pop_key(KeyCode::Z);
  assert!(input_manager.is_key_just_pressed(KeyCode::Z));
  assert!(input_manager.is_key_just_released(KeyCode::Z));
  assert!(!input_manager.is_key_pressed(KeyCode::Z));
  input_manager.update_frame_snapshot();
  assert!(!input_manager.is_key_just_pressed(KeyCode::Z));
  ```

- `pub fn is_key_just_released(&self, key: &str) -> bool` (method, since 0.3.2): Whether released this frame.
  - `key` &str: Key name. (KeyboardEvent.code, a KeyCode value)
  - returns bool: true if released since the end of the last frame.
- `pub fn update_frame_snapshot(&mut self)` (method, since 0.3.2): End-of-frame snapshot. (clears accumulated presses and releases of keys and mouse buttons, removes lifted fingers and sets the remaining fingers to stationary)
- `pub fn set_mouse_button_down(&mut self, mouse_button: MouseButton, is_down: bool)` (method, since 0.4.0): Sets a mouse button's pressed state. (called by the platform)
  - Accumulated as a press or release this frame only when it changes.
  - `mouse_button` MouseButton: Button.
  - `is_down` bool: true if pressed, false if released.
- `pub fn is_mouse_button_down(&self, mouse_button: MouseButton) -> bool` (method, since 0.4.0): Whether the mouse button is pressed.
  - `mouse_button` MouseButton: Button.
  - returns bool: true if held.
- `pub fn is_mouse_button_just_pressed(&self, mouse_button: MouseButton) -> bool` (method, since 0.4.0): Whether a mouse button was pressed this frame.
  - `mouse_button` MouseButton: Button.
  - returns bool: true if pressed since the end of the last frame. (including a press and release between frames)
- `pub fn is_mouse_button_just_released(&self, mouse_button: MouseButton) -> bool` (method, since 0.4.0): Whether the mouse button was released this frame.
  - `mouse_button` MouseButton: Button.
  - returns bool: true if released since the end of the last frame.
- `pub fn set_touch_from_left_button_only(&mut self, is_left_button_only: bool)` (method, since 0.4.0): Sets whether to pass only the left mouse button as touch. (when off (default), any button is touch)
  - When a game that uses right or middle dragging for the camera turns it on, the UI is not pressed by those buttons.
  - `is_left_button_only` bool: true to pass only the left button as touch.

  Example: Excluding the right button from touch

  ```rust
  use vanilla::{InputManager, MouseButton};
  
  let mut input_manager = InputManager::new();
  assert!(input_manager.is_touch_button(MouseButton::Right));
  input_manager.set_touch_from_left_button_only(true);
  assert!(input_manager.is_touch_button(MouseButton::Left));
  assert!(!input_manager.is_touch_button(MouseButton::Right));
  ```

- `pub fn is_touch_from_left_button_only(&self) -> bool` (method, since 0.4.0): Returns whether only the left mouse button is passed as touch.
  - returns bool: true if only the left button. (initially false)
- `pub fn is_touch_button(&self, mouse_button: MouseButton) -> bool` (method, since 0.4.0): Whether that mouse button is passed as touch. (called by the platform on mouse press and release)
  - `mouse_button` MouseButton: Button.
  - returns bool: true if passed as touch. (only Left is true if set to the left button only)
- `pub fn set_context_menu_prevented(&mut self, is_prevented: bool)` (method, since 0.4.0): Sets whether to block the canvas right-click menu. (initially true, desktop windows have no menu to block)
  - `is_prevented` bool: true to block.
- `pub fn is_context_menu_prevented(&self) -> bool` (method, since 0.4.0): Returns whether the canvas's right-click menu is blocked.
  - returns bool: true if blocked. (initially true)
- `pub fn find_touch_point(&self, identifier: i64) -> Option<&TouchPoint>` (method, since 0.4.0): Finds a touching finger. (None if none)
  - `identifier` i64: The platform's finger number.
  - returns Option<&TouchPoint>: The touching finger with that number. None if it does not exist or has already lifted.

  Example: Reading a finger position by number

  ```rust
  use vanilla::{InputManager, Vector2};
  
  let mut input_manager = InputManager::new();
  input_manager.begin_touch_point(7, Vector2::create(1.0, 2.0), Vector2::create(3.0, 4.0));
  let view_position = input_manager.find_touch_point(7).map(|touch_point| touch_point.view_position);
  assert_eq!(view_position, Some(Vector2::create(3.0, 4.0)));
  assert!(input_manager.find_touch_point(8).is_none());
  ```

- `pub fn begin_touch_point(&mut self, identifier: i64, canvas_native_position: Vector2, view_position: Vector2)` (method, since 0.4.0): A finger touches. (called by the platform, treated as a move if the number already exists)
  - `identifier` i64: The platform's finger number.
  - `canvas_native_position` Vector2: Position in logical coordinates inside the window (canvas).
  - `view_position` Vector2: Position in view coordinates.
- `pub fn move_touch_point(&mut self, identifier: i64, canvas_native_position: Vector2, view_position: Vector2)` (method, since 0.4.0): A finger moves. (a finger that touched this frame stays Began)
  - Does nothing if the number is not touching.
  - `identifier` i64: The platform's finger number.
  - `canvas_native_position` Vector2: New position in logical coordinates inside the window (canvas).
  - `view_position` Vector2: New position in view coordinates.
- `pub fn end_touch_point(&mut self, identifier: i64, canvas_native_position: Vector2, view_position: Vector2, is_cancelled: bool)` (method, since 0.4.0): A finger lifts. (removed from the touching list and put in this frame's lifted list)
  - Does nothing if the number is not touching.
  - `identifier` i64: The platform's finger number.
  - `canvas_native_position` Vector2: Lift position. (logical coordinates inside the window)
  - `view_position` Vector2: Release position. (view coordinates)
  - `is_cancelled` bool: true if cancelled (phase Cancelled), false if released (phase Ended).
- `pub fn get_ended_touch_points(&self) -> &[TouchPoint]` (method, since 0.4.0): List of fingers lifted this frame. (phase is Ended, Cancelled, position is the lift position)
  - returns &[TouchPoint]: Fingers lifted since the end of the last frame. (in lift order)
- `pub fn set_touch_points(&mut self, touch_points: Vec<TouchPoint>)` (method, since 0.4.0): Sets the list of touching fingers. (replaces it whole, phases as passed)
  - `touch_points` Vec<TouchPoint>: New finger list.
- `pub fn get_touch_points(&self) -> &[TouchPoint]` (method, since 0.4.0): List of touching fingers. (in touch order, phase is Began, Moved, Stationary)
  - returns &[TouchPoint]: Touching fingers. Empty slice if none.
- `pub fn set_touch_input(&mut self, is_touch_input: bool)` (method, since 0.4.0): Sets whether the last input was a finger. (called by the platform)
  - `is_touch_input` bool: true for a finger, false for a mouse.
- `pub fn is_touch_input(&self) -> bool` (method, since 0.4.0): Whether the last input was a finger. (false for a mouse, initially whether the device's main input is fingers. Same as the original CameraGestures.isTouchInput)
  - returns bool: true if the last input was a finger.
- `pub fn set_wheel_with_ctrl(&mut self, is_wheel_with_ctrl: bool)` (method, since 0.4.0): Sets whether the last wheel was rolled with Ctrl. (a laptop touchpad pinch also comes as a Ctrl wheel)
  - `is_wheel_with_ctrl` bool: true if with Ctrl.
- `pub fn is_wheel_with_ctrl(&self) -> bool` (method, since 0.4.0): Whether the last wheel was rolled with Ctrl.
  - returns bool: true if the last wheel event was with Ctrl. (not cleared at the end of the frame)
- `pub fn set_touch_pressed(&mut self, value: bool)` (method, since 0.3.2): Touch state. (Pressed / Released / Cancelled are on only for that frame, Moved is on while pressed, set_touch_moved)
  - `value` bool: true if pressed this frame.
- `pub fn set_touch_released(&mut self, value: bool)` (method, since 0.3.2): Sets whether released this frame. (the platform turns it on and the engine turns it off at the end of the frame)
  - `value` bool: true if released this frame.
- `pub fn set_touch_cancelled(&mut self, value: bool)` (method, since 0.3.2): Sets whether the touch was cancelled this frame. (the platform turns it on and the engine turns it off at the end of the frame)
  - `value` bool: true if cancelled this frame.
- `pub fn set_touch_moved(&mut self, value: bool)` (method, since 0.3.2): Whether being held. (on when pressed and off when released like the original, not cleared every frame, the original comment "pressed continuously until released after input")
  - `value` bool: true when pressed, false when released or cancelled.
- `pub fn is_touch_pressed(&self) -> bool` (method, since 0.3.2): Whether the touch was pressed this frame.
  - returns bool: true if pressed this frame. (the first finger or a mouse button passed as touch)

  Example: Reading press, hold and release

  ```rust
  use vanilla::InputManager;
  
  let mut input_manager = InputManager::new();
  input_manager.set_touch_pressed(true);
  input_manager.set_touch_moved(true);
  input_manager.set_touch_down(true);
  assert!(input_manager.is_touch_pressed());
  input_manager.set_touch_pressed(false);
  assert!(input_manager.is_touch_moved());
  assert!(input_manager.is_touch_down());
  input_manager.set_touch_moved(false);
  input_manager.set_touch_released(true);
  input_manager.set_touch_down(false);
  assert!(input_manager.is_touch_released());
  assert!(!input_manager.is_touch_down());
  ```

- `pub fn is_touch_released(&self) -> bool` (method, since 0.3.2): Whether the touch was released this frame.
  - returns bool: true if released this frame.
- `pub fn is_touch_cancelled(&self) -> bool` (method, since 0.3.2): Whether the touch was cancelled this frame.
  - returns bool: true if cancelled this frame. (when the platform withdrew finger input)
- `pub fn is_touch_moved(&self) -> bool` (method, since 0.3.2): Whether being held. (the original isTouchMoved, true while pressed even without moving, despite the name)
  - returns bool: true from the pressed frame until released or cancelled.
- `pub fn set_touch_down(&mut self, value: bool)` (method, since 0.3.2): Whether the touch is held. (added in the Rust version. Stays on while pressed)
  - `value` bool: true when pressed, false when released or cancelled.
- `pub fn is_touch_down(&self) -> bool` (method, since 0.3.2): Whether the touch is held.
  - returns bool: true from the pressed frame until released or cancelled. (even if held without moving)
- `pub fn set_canvas_native_input_position(&mut self, position: Vector2)` (method, since 0.3.2): Input position. (logical coordinates inside the window / view coordinates)
  - Sets the input position in logical coordinates inside the window. (called by the platform for the mouse and first finger)
  - `position` Vector2: Position in logical pixels with 0 at the top left of the canvas.
- `pub fn get_canvas_native_input_position(&self) -> Vector2` (method, since 0.3.2): Input position in logical coordinates inside the window.
  - returns Vector2: Position of the last mouse or first finger. (0 at the top left of the canvas, logical pixels, initially 0, 0)
- `pub fn set_view_input_position(&mut self, position: Vector2)` (method, since 0.3.2): Sets the input position in view coordinates. (called by the platform for the mouse and first finger)
  - `position` Vector2: Position in view coordinates.
- `pub fn get_view_input_position(&self) -> Vector2` (method, since 0.3.2): Input position in view coordinates. (the position the scene's touch_press functions receive)
  - returns Vector2: View coordinate position of the last mouse or first finger. (initially 0, 0)
- `pub fn update_all_gamepads(&mut self)` (method, since 0.3.2): Updates all gamepads.
- `pub fn connect_gamepad(&mut self, gamepad: &Gamepad)` (method, since 0.3.2): Gamepad connected.
  - `gamepad` &Gamepad: Pad to attach. (skipped if the same index is already attached)
- `pub fn disconnect_gamepad(&mut self, gamepad: &Gamepad)` (method, since 0.3.2): Gamepad disconnected.
  - `gamepad` &Gamepad: Pad to detach. (found by index, skipped if not attached)
- `pub fn get_gamepad_manager(&self) -> &GamepadManager` (method, since 0.3.2): Returns the gamepad manager.
  - returns &GamepadManager: The held gamepad manager.
- `pub fn get_gamepad_manager_mut(&mut self) -> &mut GamepadManager` (method, since 0.3.2): Returns the gamepad manager. (for changes: set_callback, connect and such)
  - returns &mut GamepadManager: The held gamepad manager. (mutable)
- `pub fn get_text_input(&self) -> &TextInput` (method, since 0.3.2): Returns the text input queue. (input fields take from it and update its state. Works with &self)
  - returns &TextInput: The held text input queue.
- `pub fn get_text_input_mut(&mut self) -> &mut TextInput` (method, since 0.3.2): Returns the text input queue. (for the platform putting in events)
  - returns &mut TextInput: The held text input queue. (mutable)
- `pub fn set_last_input_device(&mut self, input_device: InputDevice)` (method, since 0.4.0): Sets the last used input device. (called by the platform on key, mouse and finger input, also when a game uses an outside input source)
  - `input_device` InputDevice: Device.
- `pub fn get_last_input_device(&self) -> InputDevice` (method, since 0.4.0): Last used input device. (initially Touch on finger devices, otherwise Keyboard)
  - returns InputDevice: Last used device. (for choosing keyboard or pad notation for button hints)

  Example: Choosing hints by the last device

  ```rust
  use vanilla::{GamepadKind, InputDevice, InputManager};
  
  let mut input_manager = InputManager::new();
  input_manager.set_last_input_device(InputDevice::Gamepad);
  input_manager.set_last_gamepad_kind(GamepadKind::PlayStation);
  let hint = match input_manager.get_last_input_device() {
  	InputDevice::Gamepad => {
  		match input_manager.get_last_gamepad_kind() {
  			GamepadKind::PlayStation => {
  				"Cross"
  			}
  			_ => {
  				"A"
  			}
  		}
  	}
  	_ => {
  		"Enter"
  	}
  };
  assert_eq!(hint, "Cross");
  ```

- `pub fn set_last_gamepad_kind(&mut self, gamepad_kind: GamepadKind)` (method, since 0.4.0): Sets the kind of the last used gamepad.
  - `gamepad_kind` GamepadKind: Pad kind.
- `pub fn get_last_gamepad_kind(&self) -> GamepadKind` (method, since 0.4.0): Kind of the last used gamepad. (told from the name of the pad that pressed a button or tilted a stick far, initially Other)
  - returns GamepadKind: Kind of the last used pad.
- `pub fn set_prevented_keys(&mut self, keys: &[&str])` (method, since 0.4.0): Sets the keys whose browser default action is blocked. (a KeyboardEvent.code list, meaningful only on the web, not blocked while typing in a text field)
  - Replaces the previously set list whole.
  - `keys` &[&str]: List of key names to block. (KeyCode values)

  Example: Blocking the default actions of Tab and Space

  ```rust
  use vanilla::{InputManager, KeyCode};
  
  let mut input_manager = InputManager::new();
  input_manager.set_prevented_keys(&[KeyCode::TAB, KeyCode::SPACE]);
  assert!(input_manager.is_key_prevented("Tab"));
  assert!(!input_manager.is_key_prevented(KeyCode::F5));
  assert_eq!(input_manager.get_prevented_keys().len(), 2);
  ```

- `pub fn get_prevented_keys(&self) -> Vec<String>` (method, since 0.4.0): List of keys whose browser default action is blocked.
  - returns Vec<String>: Copy of the key names to block. (order is undefined)
- `pub fn is_key_prevented(&self, key: &str) -> bool` (method, since 0.4.0): Whether the key's default behavior is blocked.
  - `key` &str: Key name. (KeyboardEvent.code)
  - returns bool: true if in the list of keys to block.
- `pub fn is_typing_in_text_field(&self) -> bool` (method, since 0.4.0): Whether typing in a text field. (engine input field focus, on the web the document focus is on a text input, textarea, contenteditable, select)
  - returns bool: true if an engine input field is active or the web document focus is on a text field.
- `pub fn get_input_actions(&self) -> &InputActions` (method, since 0.4.0): Input actions. (binds keys, pad buttons and axes to action names to read them, updated every tick)
  - returns &InputActions: The held input actions.
- `pub fn get_input_actions_mut(&mut self) -> &mut InputActions` (method, since 0.4.0): Input actions. (binding, repeat, outside input sources)
  - returns &mut InputActions: The held input actions. (mutable)

## MouseButton (enum) (Clone, Copy, PartialEq, Eq, Hash, Debug)

Mouse button.

- `Left`: Left button. (slot index 0)
- `Middle`: Middle button. (wheel press, slot index 1)
- `Right`: Right button. (slot index 2)

- `pub fn get_index(&self) -> usize` (method, since 0.4.0): Button slot index.
  - returns usize: Left 0, Middle 1, Right 2.

## TouchPhase (enum) (Clone, Copy, PartialEq, Eq, Hash, Debug)

Finger phase. (Began touched this frame, Moved moved, Stationary still, Ended released, Cancelled cancelled)

- `Began`: Touched this frame. (stays Began in the frame it touched even if it moves)
- `Moved`: Moved since the last frame.
- `Stationary`: Touching and still. (update_frame_snapshot at the end of the frame changes remaining fingers to this)
- `Ended`: Lifted. (stays in get_ended_touch_points for one frame)
- `Cancelled`: Cancelled. (the platform withdrew the finger input, stays in get_ended_touch_points for one frame)

## InputDevice (enum) (Clone, Copy, PartialEq, Eq, Hash, Debug)

Last used input device.

- `Keyboard`: Keyboard.
- `Mouse`: Mouse.
- `Touch`: Finger. (touch screen)
- `Gamepad`: Gamepad. (including pad input put in by the outside input source InputActionSource)
