---
title: keyboard
slug: develop/keyboard
docTags: 
createdAt: 2025-03-11T07:07:19.526Z
---

The *keyboard* object allows you to configure the input for a USB keyboard connected to the player.

**keyboard IDL**

```text
interface keypress {
    attribute String type;
    attribute Number keyCode;
    attribute String key;
};

callback KeyboardEventCallback = void (keypress event);

interface Keyboard {
    Promise<bool> isAttached();
    Promise<void> setLayout(String layoutName);
    Promise<void> setNumLock(bool on_off);
    
    void addEventListener(String type, KeyboardEventCallback callback);
    void removeEventListener(String type, KeyboardEventCallback callback);
};
```

## Object Creation

To create a *keyboard* object, first load the `brightsign/keyboard` module using the `require()` method. Then create an instance of the *keyboard* class.

```javascript
var keyboardClass = require("@brightsign/keyboard");
var keyboard = new keyboardClass();
```

## Keypress

This interface contains the following parameters:

- `type` <font color="#704ae0">String</font>: Type is always “keypress”
- `keyCode` <font color="#704ae0">Number</font>: The ASCII keycode as number
- `key` <font color="#704ae0">String</font>: The ASCII character for the keyboard event

## Keyboard

This interface allows for detection and configuration of a USB keyboard.

### isAttached()

```javascript
Promise<bool> isAttached()
```

Returns `true` if a USB keyboard is connected to the player. This method counts a connected device as a keyboard if it reports having the following keys: "A", "Z", "0", "9", ".", and Enter.

### setLayout()

```javascript
Promise<void> setLayout(String layoutName)
```

Specifies the localized layout for the attached USB keyboard. This setting takes effect immediately and persists in the registry after a reboot. See [this table](docId\:VNJf6GnS75_lMizET3b1y) for valid keymap parameters (players are set to "us" by default).

### setNumLock()

```javascript
Promise<void> setNumLock(bool on_off)
```

Sets the numlock state for the attached USB keyboard if passed `true`. Reset the state if passed `false`.

## Example

```javascript
var KeyboardClass = require("@brightsign/keyboard");
var keyboard = new KeyboardClass();
keyboard.isAttached().then(
        function(data) {
            console.log("***Is Attached***");
            console.log(JSON.stringify(data));
        })
    .catch(
        function(data) {
            console.log(JSON.stringify(data));
        });
keyboard.setLayout("gb").then(
        function(data) {
            console.log("***Layout set***");
        })
    .catch(
        function(data) {
            console.log(JSON.stringify(data));
        }); 
```

