---
title: roUsbHidEmulator
slug: develop/rousbhidemulator
docTags: 
createdAt: 2025-03-26T17:59:47.392Z
---

This object allows you to emulate USB HID devices, but currently, the only supported type of device is a USB keyboard. 

When operating on an XT1145 or XT2145 on BOS version 9.0.157 or later, this code must be added in order to use this object:

```none
'updated code needed for new firmware
dc=CreateObject("roDeviceCustomization")
dc.ConfigureAsUsbGadget(1)
```

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

:::hint{type="danger"}
USB keyboard codes are different from PS/2, ASCII, and BrightSign keyboard codes. 
:::

## ifUsbHidEmulator 

**Enable() As Boolean&#xA0;**

Enables the HID device. This method returns `true` on success. If there's a failure, use `GetFailureReason()` to get the reason for the failure.

**KeyDown(a As Integer) As Boolean&#xA0;**

Sends a keydown event for the specified USB key code. This method returns `true` on success. If there's a failure, use `GetFailureReason()` to get the reason for the failure.

:::hint{type="info"}
USB keyboards only have 6-key rollover, therefore only six keys can be down at one time.
:::

**KeyUp(a As Integer) As Boolean&#xA0;**

Sends a keyup event for the specified USB key code. This method returns `true` on success, and returns `fails` on failure (e.g. if the specified key was not already down). If there's a failure, use `GetFailureReason()` to get the reason for the failure.

**KeyPress(a As Integer) As Boolean&#xA0;**

Equivalent to `KeyDown(key code)` followed by `KeyUp(key code)`. This method allows you to avoid leaving keys stuck down.

**Clear() As Boolean&#xA0;**

Clears all active keystrokes and modifiers.

**GetModifierState() As Object**

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

**SetModifierState(a As Object) As Boolean&#xA0;**

Sets the current modifier state as specified by an associative array. Only modifiers that are listed will cause the state to change. Modifiers will persist until changed or `Clear()` is called.

**Example**

```none
hidkey.SetModifierState({ LeftShift : true });
```

**GetLedState() As Object**

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

:::hint{type="info"}
The host may send an LED state change if a lock key (i.e. Number Lock, Capital Lock, Scrolling Lock) is pressed, generating the [roUsbHidLedEmulatorEvent](docId\:KmQrsgxeYHahPvhlsvuAd) object. The `GetLedState()` method can be used to get the current LED state without using an event.
:::

## ifUserData

**SetUserData(user\_data As Object)&#xA0;**

Sets the user data that will be returned when events are raised.

**GetUserData() As Object&#xA0;**

Returns the user data that has previously been set via `SetUserData()`. It will return `Invalid` if no data has been set.

## ifMessagePort

**SetPort(port as roMessagePort)**

Posts messages of type roUsbHidEmulatorLedEvent to the attached message port.

## ifFailureReason 

**GetFailureReason() As String&#xA0;**

Returns additional information if a method fails. 

 

