Skip to main content

Module input

Module input 

Source
Expand description

Raw keyboard, pointer and gamepads (next to the virtual pads).

ⓘ
use gasm::{input, keys};
input::set_mode(input::KEYS_RAW);              // read the keyboard directly, no keymap pads
let k = input::keys().unwrap_or_default();
if k.held(keys::SHIFT_LEFT) && k.held(keys::ARROW_LEFT) { … }
if let Some(p) = input::pointer() && p.pressed & input::MOUSE_LEFT != 0 { click(p.frame_x, p.frame_y) }

Structs§

Gamepad
Raw gamepad or joystick. With standard, W3C order: buttons 0 south, 1 east, 2 west, 3 north, 4/5 shoulders, 6/7 triggers, 8 select, 9 start, 10/11 sticks, 12-15 d-pad, 16 home; axes 0/1 left stick, 2/3 right stick (y > 0 = down).
KeyEvent
Keys
Keys held this frame; index with crate::keys constants.
Pointer

Constants§

KEYS_RAW
The runner stops mapping the keyboard to pads (gamepads still map).
MOUSE_BACK
MOUSE_FORWARD
MOUSE_LEFT
MOUSE_MIDDLE
MOUSE_RIGHT
POINTER_HIDDEN
Hide the system cursor over the game.
POINTER_LOCKED
Capture the pointer for relative motion (best effort; the browser needs a click).

Functions§

gamepad
Slot 0-3 (connection order). None if the runner has no gamepad support.
gamepad_name
Device name, if a gamepad is connected in slot.
key_events
Presses and releases since the previous frame, in order (None: no keyboard).
keys
None if the runner has no keyboard.
pointer
None if the runner has no pointer.
set_mode
KEYS_RAW | POINTER_HIDDEN | POINTER_LOCKED, any combination.