Object Creation
To create a usbhidemulator object, first load the @brightsign/usbhidemulator module using the require() method.
Code Block | ||
---|---|---|
| ||
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()
Code Block | ||
---|---|---|
| ||
Promise<void> enable() |
Enables the HID device.
disable()
Code Block | ||
---|---|---|
| ||
Promise<void> disable() |
Disables the HID device. This method is not currently supported.
clear()
Code Block | ||
---|---|---|
| ||
Promise<void> clear() |
Clears all active keystrokes and modifiers.
keyDown()
Code Block | ||
---|---|---|
| ||
Promise<void> keyDown(int keycode) |
Sends a keydown event for the specified USB key code.
keyPress()
Code Block | ||
---|---|---|
| ||
Promise<void> keyPress(int keycode) |
This is the same as keyDown() followed by keyUp().
keyUp()
Code Block | ||
---|---|---|
| ||
Promise<void> keyUp(int keycode) |
Sends a keyup event for the specified USB key code.
getLedState()
Code Block | ||
---|---|---|
| ||
Promise<LedState> getLedState() |
Returns an associative array with the current state of all LED states on the keyboard.
getModifierState()
Code Block | ||
---|---|---|
| ||
Promise<ModifierState> getModifierState() |
Returns an associative array with the current state of all modifiers (such as, shift, alt, ctrl).
setModifierState()
Code Block | ||
---|---|---|
| ||
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.
[int] keycode
Note |
---|
USB HID keyboard codes are in section 10 of 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.
[bool] optional numLock
[bool] optional capsLock
[bool] optional scrollLock
ModifierState
Listed modifiers will cause the state to change.
[bool] optional leftCtrl
[bool] optional leftShift
[bool] optional leftAlt
[bool] optional leftGui
[bool] optional rightCtrl
[bool] optional rightShift
[bool] optional rightAlt
[bool] optional rightGui
Example
Code Block | ||
---|---|---|
| ||
keyem = require('@brightsign/usbhidemulator') kbd = new keyem() kbd.addEventListener("ledupdate", function f(e) { console.log(e);}) kbd.enable() kbd.keyPress(4) |