---
sidebar_position: 0
---

# input

The `sos.input` API groups together all input-related functionality, such as remote control key events. With this API, you can
listen to key events from the remote control and handle them in your application.

## Methods

### onKeyUp()

The `onKeyUp` method sets up a listeners, which is called on every keystroke of the remote controller. For the specific logic of an
application (games for example), binding the remote control inputs can be helpful. Only a subset of all remote control keys is
supported on the specific device. Only numerical digits are guaranteed to be supported.

:::note
This feature must be tested by users on real devices.
:::

```ts expandable
onKeyUp(listener: (event: IKeyUpEvent) => void): void;
// show-more
interface IKeyUpEvent {
    type: 'keyup';
    keyCode: KeyUpEventMap;
    keyName: keyof typeof KeyUpEventMap;
}

enum KeyUpEventMap {
    UNKNOWN = 0,
    NUM_0 = 1,
    NUM_1 = 2,
    NUM_2 = 3,
    NUM_3 = 4,
    NUM_4 = 5,
    NUM_5 = 6,
    NUM_6 = 7,
    NUM_7 = 8,
    NUM_8 = 9,
    NUM_9 = 10,
    ARROW_LEFT = 11,
    ARROW_UP = 12,
    ARROW_RIGHT = 13,
    ARROW_DOWN = 14,
    YELLOW = 16,
    BLUE = 17,
    RED = 18,
    GREEN = 19,
    VOLUME_DOWN = 20,
    VOLUME_UP = 30,
    POWER = 31,
    POWER_OFF = 32,
    HOME = 33,
    EXIT = 34,
    RETURN = 35,
    BACKSPACE = 36,
    LOCK = 37
}

```

#### Params

| Name       | Type                           | Required         | Description                                                      |
|------------|--------------------------------|------------------|------------------------------------------------------------------|
| `listener` | `(event: IKeyUpEvent) => void` |  <div>Yes</div>  | The listener function that will be called on every key up event. |

#### Return value

Resolves when the listener is successfully set up.

#### Possible errors


- If listener is not valid function.
- If listener is unregistered.

<Separator />

### removeEventListener()

The `removeEventListener()` method removes all event listeners for a specific event (only `keyup` is supported).

```ts expandable
removeEventListener(event: 'keyup', listener: (...args: any[]) => void): void;
```

#### Params

| Name       | Type                       | Required         | Description                                                                             |
|------------|----------------------------|------------------|-----------------------------------------------------------------------------------------|
| `event`    | `"keyup"`                  |  <div>Yes</div>  | The name of the event to remove the listener for. Currently, only `keyup` is supported. |
| `listener` | `(...args: any[]) => void` |  <div>Yes</div>  | The listener function to remove.                                                        |

#### Return value

Resolves when the listener is successfully removed.

<Separator />

### removeEventListeners()

The `removeEventListeners()` method removes all event listeners bind on `sos.input` object.

```ts expandable
removeEventListeners(): void;
```

## API Example

```ts
import { sos } from '@signageos/front-applet';

void sos.onReady(async () => {
	sos.input.onKeyUp((keyUpEvent) => {
		console.log(`Pressed: ${keyUpEvent.keyCode} (${keyUpEvent.keyName})`);
	});
});

```