See Also: Input
The Input subsystem provides keyboard, mouse, joystick and touch input both via a polled interface and events. This subsystem is also used for querying whether the application window has input focus or is minimized.
The subsystem is always instantiated, even in headless mode, but is active only once the application window has been created. Once active, the subsystem takes over the operating system mouse cursor. It will be hidden by default, so the UI should be used to render a software cursor if necessary. For editor-like applications the operating system cursor can be made visible by calling Input.SetMouseVisible.
You can subscribe to these events by using one of the SubscribeToXxx methods in UrhoObject:
- MouseButtonUp: a mouse button was released.
- MouseButtonDown: a mouse button was pressed.
- MouseMove: the mouse moved.
- MouseWheel: the mouse wheel moved.
- KeyUp: a key was released.
- KeyDown: a key was pressed.
- TextInput: a string of translated text input in UTF8 format. May contain a single character or several.
- JoystickConnected: a joystick was plugged in.
- JoystickDisconnected: a joystick was disconnected.
- JoystickButtonDown: a joystick button was pressed.
- JoystickButtonUp: a joystick button was released.
- JoystickAxisMove: a joystick axis was moved.
- JoystickHatMove: a joystick POV hat was moved.
- TouchBegin: a finger touched the screen.
- TouchEnd: a finger was lifted from the screen.
- TouchMove: a finger moved on the screen.
- GestureRecorded : recording a touch gesture is complete.
- GestureInput : a touch gesture was recognized.
- MultiGesture : a multi-finger pinch/rotation touch gesture is underway.
- DropFile : a file was drag-dropped on the application window.
- InputFocus : application input focus or window minimization state changed.
- MouseVisibleChanged : the visibility of the operating system mouse cursor was changed.
- ExitRequested : application exit was requested (eg. with the window close button.)
Keyboard and Mouse Input
Key events include both the symbolic keycode ("Key") that depends on the keyboard layout, the layout- and operating system-independent SDL scancode ("Scancode"), and the true operating system-specific raw keycode ("Raw").
The input polling API differentiates between the initiation of a key/mouse button press, and holding the key or button down. Input.GetKeyPress and Input.GetMouseButtonPress return true only for one frame (the initiation) while Input.GetKeyDown and Input.GetMouseButtonDown return true as long as the key or button is held down. To check whether keys are down or pressed by scancode, use Input.GetScancodeDown and Input.GetScancodePress. Functions also exist for converting keycodes to scancodes or vice versa, or getting key names. See for example Input.GetKeyName and Input.GetKeyFromScancode.
The operating system mouse cursor can be used in four modes which can be switched with Input.MouseMode:
- Absolute: is the default behaviour, allowing the toggling of operating system cursor visibility and allowing the cursor to escape the window when visible. When the operating system cursor is invisible in absolute mouse mode, the mouse is confined to the window. If the operating system and UI cursors are both invisible, interaction with the user interface will be limited (for example, drag move and drag end events will not trigger). Setting this value to Absolute will call SetMouseGrabbed(false).
- Relative: sets the operating system cursor to invisible and confines the cursor to the window. The operating system cursor cannot be set to be visible in this mode via SetMouseVisible(), however changes are tracked and will be restored when another mouse mode is set. When the virtual cursor is also invisible, UI interaction will still function as normal (eg: drag events will trigger). Setting this will call SetMouseGrabbed(true).
- Wrap: grabs the mouse from the operating system and confines the operating system cursor to the window, wrapping the cursor when it is near the edges. Setting this will call SetMouseGrabbed(true).
- Free: does not grab/confine the mouse cursor even when it is hidden. This can be used for cases where the cursor should render using the operating system outside the window, and perform custom rendering (with SetMouseVisible(false)) inside.
Plugged in joysticks will begin sending input events automatically. Each joystick will be assigned a joystick ID which will be used in subsequent joystick events, as well as for retrieving the joystick state. Use Input.GetJoystick to retrieve the joystick state by ID. In case you do not have the ID, you can also use Input.GetJoystickByIndex which uses a zero-based index; see Input.NumJoystick for the number of currently connected joysticks. The ID, as well as the joystick name, can be looked up from the joystick state.
If the joystick model is recognized by SDL as a game controller the buttons and axes mappings utilize known constants such as CONTROLLER_BUTTON_A or CONTROLLER_AXIS_LEFTX without having to guess them. Use .() to distinguish between a game controller and an unrecognized joystick.
On platforms that support the accelerometer, it will appear as a "virtual" joystick.
On platforms where touch input is available, touch begin/end/move events will be sent, as well as multi-gesture events with pinch/rotation delta values when more than one finger is pressed down. The current finger touches can also be accessed via a polling API: Input.NumTouches and Urho.Input.GetTouch.
Touch gestures can be recorded using SDL's inbuilt $1 gesture recognition system. Use Input.RecordGesture to start recording. The following finger movements will be recorded until the finger is lifted, at which point the recording ends and the GestureRecorded event is sent with the hash ID of the new gesture. The current in-memory gesture(s) can be saved or loaded as binary data.
Whenever a recognized gesture is entered by the user, the GestureInput event will be sent. In addition to the ID of the best matched gesture, it contains the center position and an error metric (lower = better) to help filter out false gestures.
Note that all recorded (whether saved or not) and loaded gestures are held in-memory. Two additional functions are available to clear them: Input.RemoveGesture to selectively clear a gesture by its ID and Input.RemoveAllGestures to clear them all.
Touch input can also emulate a virtual joystick by displaying on-screen buttons. See the function Input.AddScreenJoystick.
Touch emulation can be used to test mobile applications on a desktop machine without a touch screen. See Input.TouchEmulation. When touch emulation is enabled, actual mouse events are no longer sent and the operating system mouse cursor is forced visible. The left mouse button acts as a moving finger, while the rest of the mouse buttons act as stationary fingers for multi-finger gestures. For example pressing down both left and right mouse buttons, then dragging the mouse with the buttons still pressed would emulate a two-finger pinch zoom-in gesture.
On platforms that support it (such as Android) an on-screen virtual keyboard can be shown or hidden. When shown, keypresses from the virtual keyboard will be sent as text input events just as if typed from an actual keyboard. Show or hide it by calling .etScreenKeyboardVisible. The UI subsystem can also automatically show the virtual keyboard when a line editing element is focused, and hide it when defocused. This behavior can be controlled by calling SetUseScreenKeyboard.
On Windows the user must first touch the screen once before touch input is activated. Trying to record or load touch gestures will fail before that.
Assembly: Urho (in Urho.dll)
Assembly Versions: 220.127.116.11
The members of Urho.Input are listed below.
See Also: UrhoObject
|Enabled||Boolean. Controls whether input is enabled or disabled.|
|[read-only]||Minimized||Boolean. Return whether application window is minimized.|
|[read-only]||MouseGrabbed||Boolean. Return whether the mouse is currently being grabbed by an operation.|
|[read-only]||MouseLocked||Boolean. Return whether the mouse is locked to the window|
|[read-only]||MouseMode||MouseMode. Return the mouse mode. Or Set the mouse mode.|
|[read-only]||MouseMove||IntVector2. Return mouse movement since last frame.|
|[read-only]||MouseMoveWheel||Int32. Return mouse wheel movement since last frame.|
|[read-only]||MouseMoveX||Int32. Return horizontal mouse movement since last frame.|
|[read-only]||MouseMoveY||Int32. Return vertical mouse movement since last frame.|
|[read-only]||MousePosition||IntVector2. Return mouse position within window. Should only be used with a visible mouse cursor.|
|[read-only]||MouseVisible||Boolean. Return whether the operating system mouse cursor is visible.|
|[read-only]||NumJoysticks||UInt32. Return number of connected joysticks.|
|[read-only]||NumTouches||UInt32. Return number of active finger touches.|
|[read-only]||Qualifiers||Int32. Return the currently held down qualifiers.|
|[read-only]||ScreenKeyboardSupport||Boolean. Return whether on-screen keyboard is supported.|
|ScreenKeyboardVisible||Boolean. Return whether on-screen keyboard is being shown; On platform that support it, setting this property displays the on-screen keyboard.|
|ToggleFullscreen||Boolean. Return whether fullscreen toggle is enabled. Or Set whether ALT-ENTER fullscreen toggle is enabled.|
|TouchEmulation||Boolean. Return whether touch emulation is enabled. Or Set touch emulation by mouse. Only available on desktop platforms. When enabled, actual mouse events are no longer sent and the mouse cursor is forced visible.|
|Type||StringHash. Urho's type system type.|
|TypeName||String. Urho's low-level type name.|
|TypeNameStatic||String. Urho's low-level type name, accessible as a static method.|
|TypeStatic||StringHash. Urho's low-level type, accessible as a static method.|
Center the mouse position.
Return joystick state by ID, or null if does not exist.
Return joystick state by index, or null if does not exist. 0 = first connected joystick.
Check if a key is held down.
Return keycode from key name.
Return keycode from scancode.
Return name of key from keycode.
Check if a key has been pressed on this frame.
Check if a mouse button is held down.
Check if a mouse button has been pressed on this frame.
Check if a qualifier key is held down.
Check if a qualifier key has been pressed on this frame.
Check if a key is held down by scancode.
Return scancode from keycode.
Return scancode from key name.
Return name of key from scancode.
Check if a key has been pressed on this frame by scancode.
Return active finger touch by index.
Return whether application window has input focus.
Return whether a virtual joystick is visible.
Begin recording a touch gesture. Return true if successful. The E_GESTURERECORDED event (which contains the ID for the new gesture) will be sent when recording finishes.
Remove all in-memory gestures.
Remove an in-memory gesture by ID. Return true if was found.
Remove screen joystick by instance ID. Return true if successful. This method should only be called in main thread.
Reset the mouse grabbed to the last unsuppressed SetMouseGrabbed call
Reset the last mouse mode that wasn't suppressed in SetMouseMode
Reset last mouse visibility that was not suppressed in SetMouseVisible.
Set whether the operating system mouse cursor is visible. When not visible (default), is kept centered to prevent leaving the window. Mouse visibility event can be suppressed-- this also recalls any unsuppressed SetMouseVisible which can be returned by ResetMouseVisible().
Set whether the virtual joystick is visible.
Subscribes to the DropFile event raised by the Input.
Subscribes to the ExitRequested event raised by the Input.
Subscribes to the GestureInput event raised by the Input.
Subscribes to the GestureRecorded event raised by the Input.
Subscribes to the InputFocus event raised by the Input.
Subscribes to the JoystickAxisMove event raised by the Input.
Subscribes to the JoystickButtonDown event raised by the Input.
Subscribes to the JoystickButtonUp event raised by the Input.
Subscribes to the JoystickConnected event raised by the Input.
Subscribes to the JoystickDisconnected event raised by the Input.
Subscribes to the JoystickHatMove event raised by the Input.
Subscribes to the KeyDown event raised by the Input.
Subscribes to the KeyUp event raised by the Input.
Subscribes to the MouseButtonDown event raised by the Input.
Subscribes to the MouseButtonUp event raised by the Input.
Subscribes to the MouseModeChanged event raised by the Input.
Subscribes to the MouseMoved event raised by the Input.
Subscribes to the MouseVisibleChanged event raised by the Input.
Subscribes to the MouseWheel event raised by the Input.
Subscribes to the MultiGesture event raised by the Input.
Subscribes to the TextInput event raised by the Input.
Subscribes to the TouchBegin event raised by the Input.
Subscribes to the TouchEnd event raised by the Input.
Subscribes to the TouchMove event raised by the Input.
|TryGetJoystickState(UInt32, out JoystickState)|
Poll for window messages. Called by HandleBeginFrame().