[−][src]Crate riddle_input
Riddle crate dealing with user input (keyboard, mouse, gamepad).
Built largely on the back of gilrs
and its dependencies for controller support,
and consumes system events from a riddle-platform
compatible system (winit
).
The primary functions of this crate is to convert incoming input event streams in to a queryable immediate-mode-like API, and to unify the incoming event streams in to a single input event stream.
Riddle Example
The recommended way to use this crate is through the main riddle
crate.
Riddle exposes this crate through riddle::input
.
use riddle::{*, platform::*, input::*}; fn main() -> Result<(), RiddleError> { let rdl = RiddleLib::new()?; let window = WindowBuilder::new().build(rdl.context())?; rdl.run(move |rdl| { match rdl.event() { Event::Input(InputEvent::KeyDown { .. }) => rdl.quit(), _ => (), } }) }
Direct Example
If you don't want to depend on riddle
, you can use this crate directly. In order to have
the crate function, appropriate riddle_platform_common::PlatformEvent
s must be sent
to the input system via the EventPub
it is constructed with.
use riddle_input::*; use riddle_common::eventpub::*; use riddle_platform_common::*; fn main() -> Result<(), InputError> { let platform_events: EventPub<PlatformEvent> = EventPub::new(); let (input_system, mut main_thread_state) = InputSystem::new(&platform_events)?; platform_events.dispatch(PlatformEvent::MouseButtonDown{ window: WindowId::new(0), button: MouseButton::Left}); main_thread_state.process_input(); let input_events: Vec<InputEvent> = input_system.take_input_events(); Ok(()) }
Structs
GamePadId | An identifier mapping to a particular gamepad, used for querying state from |
InputMainThreadState | The portion of the input system that needs to remain on a single thread. |
InputSystem | The Riddle input system core state, along with |
InputSystemHandle | |
InputSystemWeak | |
KeyboardModifiers | A snapshot of which keyboard modifiers are currently pressed. |
LogicalPosition | A 2d position in logical screen units. |
Enums
GamePadAxis | GamePad axis identifiers. |
GamePadButton | GamePad Button identifiers. |
InputError | |
InputEvent | |
MouseButton | Mouse button identifiers. |
Scancode | Supported scancodes. |
VirtualKey | Supported virtual keys. |