---
title: usbhidemulator
slug: develop/usbhidemulator
docTags: 
createdAt: 2025-03-27T16:58:59.390Z
---

The *usbhidemulator* allows you to emulate USB HID devices. USB keyboards are currently the only supported device type. 

BrightSign players with USB-C (except for LS3 and LS4) can use this object.

**usbhidemulator IDL**

```javascript
[                                                                                                                                                                                                                                
    constructor(String path, String type)                                                                            
] interface UsbHidEmulator {                                                                                               
    Promise<void> enable();                                                                                                
    Promise<void> disable();                                                                                               
    Promise<void> clear();                                                                                                 
    Promise<void> keyDown(int keycode);  
	Promise<void> keyPress(int keycode);                                                                                  
    Promise<void> keyUp(int keycode);                                                                                      
    Promise<LedState> getLedState();                                                                                       
    Promise<ModifierState> getModifierState();                                                                             
    Promise<void> setModifierState(ModifierState)                                                                          
};

interface LedState {
    [optional] attribute bool numLock;
    [optional] attribute bool capsLock;
    [optional] attribute bool scrollLock;
};

interface ModifierState {
    [optional] attribute bool leftCtrl;
    [optional] attribute bool leftShift;
    [optional] attribute bool leftAlt;
    [optional] attribute bool leftGui;
    [optional] attribute bool rightCtrl;
    [optional] attribute bool rightShift;
    [optional] attribute bool rightAlt;
    [optional] attribute bool rightGui;
};                                                                                                                          
                                                                                                                           
```

## Object Creation

To create a *usbhidemulator* object, first load the *@brightsign/usbhidemulator* module using the *require()* method.

```javascript
keyem = require('@brightsign/usbhidemulator')
kbd = new keyem()
```

## UsbHideEmulator

Use this interface to configure a *usbhidemulator* interface. The *usbhidemulator* class also generates "ledupdate" events which can be listened for with *AddEventListener().*

**enable()**

```javascript
Promise<void> enable()
```

Enables the HID device.

**disable()**

```javascript
Promise<void> disable()
```

Disables the HID device. This method is not currently supported.

**clear()**

```javascript
Clears all active keystrokes and modifiers.
```

Clears all active keystrokes and modifiers.

**keyDown()**

```javascript
Promise<void> keyDown(int keycode)
```

Sends a keydown event for the specified USB key code.

**keyPress()**

```javascript
Promise<void> keyPress(int keycode)
```

This is the same as keyDown() followed by keyUp().

**keyUp()**

```javascript
Promise<void> keyUp(int keycode)
```

Sends a keyup event for the specified USB key code.

**getLedState()**

```javascript
Promise<LedState> getLedState()
```

Returns an associative array with the current state of all LED states on the keyboard.

**getModifierState()**

```javascript
Promise<ModifierState> getModifierState()
```

Returns an associative array with the current state of all modifiers (such as, shift, alt, ctrl).

**setModifierState()**

```javascript
Promise<ModifierState> setModifierState(ModifierState)
```

Sets the current modifier state as specified by an associative array. Only modifiers that are listed will cause the state to change.

## Keycode

This interface contains the USB key code. 

- `keycode`<font color="#6554c0"> int</font>

:::hint{type="warning"}
USB HID keyboard codes are in section 10 of [www.usb.org/sites/default/files/documents/hut1\_12v2.pdf](http://www.usb.org/sites/default/files/documents/hut1_12v2.pdf).
:::

## LedState

This interface sends an LED state change if number lock, capital lock, or scroll lock is pressed.

- `numLock` <font color="#6554c0">bool</font> <font color="#01a0af">optional</font>
- `capsLock` <font color="#6554c0">bool</font> <font color="#01a0af">optional</font>
- `scrollLock` <font color="#6554c0">bool </font><font color="#01a0af">optional</font>

## ModifierState

Listed modifiers will cause the state to change.

- `leftCtrl` <font color="#6554c0">bool</font> <font color="#01a0af">optional</font>
- `leftShift`<font color="#6554c0"> bool</font> <font color="#01a0af">optional</font>
- `leftAlt` <font color="#6554c0">bool</font> <font color="#01a0af">optional</font>
- `leftGui` <font color="#6554c0">bool</font> <font color="#01a0af">optional</font>
- `rightCtrl` <font color="#6554c0">bool</font> <font color="#01a0af">optional</font>
- `rightShift` <font color="#6554c0">bool</font> <font color="#01a0af">optional</font>
- `rightAlt` <font color="#6554c0">bool</font> <font color="#01a0af">optional</font>
- `rightGui` <font color="#6554c0">bool</font> <font color="#01a0af">optional</font>

## Example

```javascript
keyem = require('@brightsign/usbhidemulator')
kbd = new keyem()
kbd.addEventListener("ledupdate", function f(e) { console.log(e);})
kbd.enable()

kbd.keyPress(4)
```

