Input
INCLUDE 'os/in/-'
The os::in
library exposes user input to programs.
ENUM Key {}
ENUM KeyEvent {}
TYPE ScanCode := UINT;
TYPE MouseButton := U1;
TYPE ControllerButton := U1;
::os::in MASK Target
{
on_mouse_button(MouseButton, KeyEvent) VOID;
on_key(Key #*, ScanCode, KeyEvent) VOID;
on_controller_button(ControllerButton, KeyEvent) VOID;
on_joystick(stick: U2, x: SINGLE, y: SINGLE) VOID;
on_cursor_enter() VOID;
on_cursor(x: S4, y: S4) VOID;
on_cursor_leave() VOID;
on_focus() VOID;
on_blur() VOID;
}
::os::in Source VIRTUAL
{
VIRTUAL connect(Target \) BOOL;
VIRTUAL poll(timeout_seconds: DOUBLE) @ VOID;
}
The os::in::Target
interface qualifies an object as the recipient of user input events.
By using this standard abstraction, input handling can easily be decoupled from actual input events, and thus simulated and tested.
All input sources should inherit from os::in::Source
.
An input target can register itself with a source via connect()
, which returns whether the target was accepted.
Via os::in::Source::poll(timeout)
, an input target can wait for inputs from a source.
Note that events can also be triggered even if poll()
wasn't called.