Modules and Features
Plugins can extend their capabilities beyond basic USB reads and writes using two systems: Modules and Features. Understanding the difference between them helps you discover what’s available and use the right mechanism for the job.
Modules vs Features
Section titled “Modules vs Features”| Modules | Features | |
|---|---|---|
| How to use | import { x } from "@SignalRGB/name" | device.addFeature("name") in Initialize() |
| Purpose | Utility services (networking, encoding, system info) | Device capabilities (battery, input injection) |
| Namespace | Module’s own exported names | device.featureName.* |
| Instances | One per plugin | Can have multiple |
Available Modules
Section titled “Available Modules”Import these at the top of your plugin file.
| Import path | Purpose |
|---|---|
@SignalRGB/serial | Serial/COM port communication |
@SignalRGB/tcp | TCP socket communication |
@SignalRGB/udp | UDP socket communication |
@SignalRGB/base64 | Base64 encoding and decoding |
@SignalRGB/performance | Performance profiling and frame timers |
@SignalRGB/appInfo | SignalRGB application version info |
@SignalRGB/systeminfo | System hardware information |
@SignalRGB/permissions | Check user permission state |
See Advanced Communication for serial, tcp, and udp usage examples.
Available Features
Section titled “Available Features”Call device.addFeature("name") in your Initialize() export. The feature creates a global object with the same name as the feature.
| Feature name | Namespace | Purpose |
|---|---|---|
"keyboard" | keyboard | Inject keystrokes or route keyboard events to SignalRGB macros |
"mouse" | mouse | Inject mouse input or route mouse events to SignalRGB macros |
"battery" | battery | Report battery level and charge state for wireless devices |
"dtls" | dtls | DTLS-encrypted UDP with PSK authentication |
Keyboard Feature
Section titled “Keyboard Feature”For plugins that represent keyboard devices. Lets you inject real keystrokes into the OS or fire events that can trigger SignalRGB macros.
export function Initialize() { device.addFeature("keyboard");}keyboard.sendHid(vkCode, options)
Section titled “keyboard.sendHid(vkCode, options)”Sends a raw keystroke directly to the operating system via keybd_event. The key appears as real input to all applications — it bypasses the macro system entirely.
| Parameter | Type | Description | Example |
|---|---|---|---|
| vkCode | Number | Windows Virtual Key code | 0x41 (A key) |
| options.released | Boolean (required) | true for key-up, false for key-down | false |
keyboard.sendHid(0x41, { released: false }); // Press Akeyboard.sendHid(0x41, { released: true }); // Release Akeyboard.sendEvent(eventData, eventType)
Section titled “keyboard.sendEvent(eventData, eventType)”Routes a keyboard event through the SignalRGB macro system. Macros with an onKey trigger can match these events. Does not inject a real keystroke — only SignalRGB macros see this event.
The macro system automatically enriches the event with live modifier state (Ctrl, Shift, Alt, Win) from the physical keyboard before dispatching it.
| Parameter | Type | Description | Example |
|---|---|---|---|
| eventData | Object or String | Event data. Include key (string name) and optionally keyCode (number) for key matching. | { key: "A", keyCode: 0x41 } |
| eventType | String | Event type label | "KeyPress" |
keyboard.sendEvent({ key: "A", keyCode: 0x41, released: false }, "KeyPress");Macro scripts receive event.Sender (the plugin’s UID) and event.SenderType ("Device"), so they can distinguish plugin-sourced events from real hardware keystrokes.
Mouse Feature
Section titled “Mouse Feature”For plugins that represent mouse or pointer devices.
export function Initialize() { device.addFeature("mouse");}mouse.sendHid(buttonCode, options)
Section titled “mouse.sendHid(buttonCode, options)”Sends a raw mouse event to the OS via SendInput. Mouse movement (MOUSEEVENTF_MOVE, MOUSEEVENTF_ABSOLUTE) is blocked for safety.
| Parameter | Type | Description |
|---|---|---|
| buttonCode | Number | Windows MOUSEEVENTF_* flag |
| options.XButton | Number | Required for X-button events — 1 (X1) or 2 (X2) |
| options.WheelDelta | Number | Required for scroll wheel events — positive scrolls up, negative scrolls down |
Common button codes:
| Code | Constant | Description |
|---|---|---|
0x0002 | MOUSEEVENTF_LEFTDOWN | Left button press |
0x0004 | MOUSEEVENTF_LEFTUP | Left button release |
0x0008 | MOUSEEVENTF_RIGHTDOWN | Right button press |
0x0010 | MOUSEEVENTF_RIGHTUP | Right button release |
0x0020 | MOUSEEVENTF_MIDDLEDOWN | Middle button press |
0x0040 | MOUSEEVENTF_MIDDLEUP | Middle button release |
0x0800 | MOUSEEVENTF_WHEEL | Vertical scroll |
0x01000 | MOUSEEVENTF_HWHEEL | Horizontal scroll |
0x0080 | MOUSEEVENTF_XDOWN | X-button press (requires XButton option) |
0x0100 | MOUSEEVENTF_XUP | X-button release (requires XButton option) |
// Left clickmouse.sendHid(0x0002, {}); // downmouse.sendHid(0x0004, {}); // up
// Scroll up one notchmouse.sendHid(0x0800, { WheelDelta: 120 });
// X1 button pressmouse.sendHid(0x0080, { XButton: 1 });mouse.sendHid(0x0100, { XButton: 1 });mouse.sendEvent(eventData, eventType)
Section titled “mouse.sendEvent(eventData, eventType)”Routes a custom mouse event through the SignalRGB macro system. Macro scripts with an onMouse trigger can match these events. Does not inject any OS-level mouse input.
mouse.sendEvent({ button: "LeftClick" }, "ButtonPress");Battery Feature
Section titled “Battery Feature”For wireless devices that report battery status. After adding the feature, update the battery level and state whenever your device reports them.
export function Initialize() { device.addFeature("battery");}Setting Battery State
Section titled “Setting Battery State”| Method | Description |
|---|---|
battery.setBatteryLevel(level) | Set battery percentage (0–100) |
battery.setBatteryState(state) | Set the charge state using a state constant |
State constants (access via battery.<name>):
| Constant | Description |
|---|---|
battery.disabled | Battery reporting disabled |
battery.unknown | State not yet known |
battery.draining | Running on battery |
battery.charging | Charging via cable |
battery.fullCharging | Charging and already full |
battery.full | Full charge, not charging |
battery.wirelessCharging | Wireless charging |
Reading Battery State
Section titled “Reading Battery State”These properties reflect the last values set:
| Property | Type | Description |
|---|---|---|
battery.batteryLevel | Number | Current level (0–100) |
battery.batteryState | Number | Current state value |
battery.stateString | String | Human-readable state label |
Battery Example
Section titled “Battery Example”export function Initialize() { device.addFeature("battery");}
export function Render() { // Non-blocking read — check if the device sent a battery report this frame var data = device.read([], 64, 0);
if(device.getLastReadSize() > 0 && data[0] === 0x02) { var level = data[1]; // 0–100 var charging = data[2] === 0x01;
battery.setBatteryLevel(level); battery.setBatteryState( charging ? battery.charging : battery.draining ); }}