Basic example with Node
Before you get started check out our: Getting started with Node guide.
This example shows you how you can change RGB from Node.js. Don’t want to use javascript? Most languages have easy access to DLL functions. For example python For example python.
Getting started
To get started open a command prompt in a code directory and type:
Git clone https://github.com/WootingKb/wooting-rgb-example.git
After you have the project run:
Npm install
You’re now ready to run the examples.
Basic example
First take a look at “basic-example.js”. Start it by running:
Node basic-example.js
With the default values you should see the W-key light purple for 2 seconds
Code description:
We first define the functions that we want to use from the library. In this case we want to check if a keyboard is connected, change the colors of single keys and reset the keyboard when we’re done.
const ffi = require("ffi") // Define the functions from the DLL const wootingRgb = ffi.Library('./libs/wooting-rgb-control.dll', { "wooting_rgb_kbd_connected": [ 'bool', [] ], "wooting_rgb_reset": [ 'bool', [] ], "wooting_rgb_direct_set_key": [ 'bool', ['uint8', 'uint8', 'uint8', 'uint8', 'uint8'] ], "wooting_rgb_direct_reset_key": [ 'bool', ['uint8', 'uint8'] ], });
We then do our first call from the DLL, check if a keyboard is connected. If it is not connected we log something and exit the program.
const keyboardConnected = wootingAnalog.wooting_kbd_connected() if(!keyboardConnected) { console.log('Keyboard not connected')
Finally we get to the part where we actually change the W-key color. Remember from the array (link) the W key is on row 2 and column 2. We call the set function to change the color directly. We then use Node’s “setTimeOut” to reset the same key after 2 seconds.
// Set the key to a color and reset it after 2 seconds (2000 milliseconds) wootingRgb.wooting_rgb_direct_set_key(row, column, red, green, blue) setTimeout(() => wootingRgb.wooting_rgb_direct_reset_key(row, column), 2000)
At the end we still have have some code to make sure the keyboard always resets to the profile colors when we exit the program.
// Make sure the lights go back to normal after process exits process.on('exit', (code) => { wootingRgb.wooting_rgb_reset() })
Pro-tip
As a fun example you can now make a simple discord integration with the keyboard. See for a guide how to set up your bot.