Use the Input module to listen for key-based input events in your You.i React Native app. The module consists of the following methods:
AddEventListener()
RemoveEventListener()
The Input module object returned by callback contains the following elements:
Usage | Description |
---|---|
JSON.stringify(keyEvent.screenRect) |
|
keyEvent.altHeld | Alt key pressed or not (Boolean) |
keyEvent.character | A number representing the character value for the pressed key. Note that keyEvent.keyValue is a different representation of the same information. |
keyEvent.controlHeld | Control key pressed or not (Boolean) |
keyEvent.eventType | Key event type (Up or Down) |
keyEvent.eventContext |
"activation" (string)"cancellation" (string)null
|
keyEvent.held | Button pressed down or not (Boolean) |
keyEvent.keyCode | A value for the key event that was triggered. You can find a list of event values, including values for consoles like PlayStation4 or Xbox, in the input.js file at youiengine/<version>/packages/react-native-youi/Libraries/react-native-youi/Utilities/Input.js For events that don’t appear in input.js , the keyCode value is Unidentified , and keyEvent.keyValue contains the character value for the key that was pressed (corresponding to CYIKeyEvent::m_keyValue ). |
keyEvent.keyLocation | Key location; one of standard , left , numpad , mobile , or joystick
|
keyEvent.keyValue | A number representing the character value of the pressed key. Enables you to listen for platform-specific keys not listed in input.js , such as the fn button on macOS, or the Recall button on a TV remote. For example, the “A” key has a keyValue of 65 (the ASCII value for “A”).Note that keyEvent.character is a different representation of the same information. |
keyEvent.metaHeld | Meta pressed or not (Boolean) |
keyEvent.shiftHeld | Shift key pressed or not (Boolean) |
keyEvent.tag | React tag |
TextInput
component is hidden in the app for listening to key events.
But if you use the Input module, you don’t need to hide the TextInput
component.SiriRemoteClickUp
, SiriRemoteClickDown
, SiriRemoteClickLeft
, or SiriRemoteClickRight
.
This issue does not occur when using the simulated remote.Both of the code options shown below allow you to add event listeners; these examples use the alphanumeric F1 key, and would return a callback for keyEvent.keyCode
as described in the table above.
import {
Input
} from '@youi/react-native-youi';
Input.addEventListener("F1", this.myFunction);
import {
Input
} from '@youi/react-native-youi';
Input.addEventListener(Input.Event.F1, this.myFunction);