Input Module

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
  • X coordinate
  • Y coordinate
  • Width of the rectangle
  • Height of the rectangle
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)

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 keyCodevalue 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

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.

Example 1

import {
} from '@youi/react-native-youi';   

Input.addEventListener("F1", this.myFunction);

Example 2

import {
} from '@youi/react-native-youi';   

Input.addEventListener(Input.Event.F1, this.myFunction);