Skip to main content

Module input

Module input 

Source
Expand description

Browser input → blinc_platform::InputEvent conversion

Every function in this module is pure (no web-sys dep) so it compiles and unit-tests on every host. The wasm-bindgen runner module reads web_sys::MouseEvent / KeyboardEvent / WheelEvent / TouchEvent fields, then hands the primitive values (button index, key string, dx/dy, …) to the helpers here.

Splitting the conversion this way mirrors how blinc_platform_desktop::input keeps winit out of its convert_* signatures by passing in primitives where possible.

§Key string mapping

The W3C KeyboardEvent.key value is a string like "ArrowLeft", "Enter", "a", or "F1". This module’s convert_key_from_dom consumes that string directly. The full set of named keys is specified at https://www.w3.org/TR/uievents-key/#named-key-attribute-values.

Functions§

convert_key_from_dom
Convert a W3C KeyboardEvent.key string to a Blinc Key.
convert_mouse_button
Convert a W3C MouseEvent.button value to a Blinc MouseButton.
convert_pointer_button
Pointer events expose pointer.button as i32 rather than i16. Convenience wrapper around convert_mouse_button.
keyboard_event
Build a keyboard event with state + modifiers.
modifiers_from_keyboard
Same as modifiers_from_mouse but spelled differently for keyboard events. Browsers expose the identical four booleans on both event types — we keep separate names purely for call-site readability.
modifiers_from_mouse
Build a Modifiers struct from the four boolean fields a web_sys::MouseEvent exposes (shiftKey, ctrlKey, altKey, metaKey). Kept primitive so it’s testable without web-sys.
mouse_moved
Build a Mouse(Moved) event from canvas-local coordinates.
mouse_pressed
Build a Mouse(ButtonPressed) event from canvas-local coordinates.
mouse_released
Build a Mouse(ButtonReleased) event from canvas-local coordinates.