Skip to content

Wooting dev portal

The resource guide for Wooting code

Wooting dev portal

  • Introduction developer portal
  • Analog SDK guide
    • Introduction
    • Analog API description
    • Basic example with Node
    • Advanced example with Node
    • Unity example
  • RGB SDK guide
    • Introduction
    • RGB API description
    • Basic example with Node
    • Advanced example with Node
  • Spotlight
Search

Basic example with Node

First posted: June 27, 2018February 25, 2020Filed under: Wooting RGB SDK Guide

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.

 

 

 

Wooting RGB SDK Guide

Post navigation

Previous Post:

Advanced example with Node

Next Post:

RGB API description

About the Author

Erik Stakenborg

All posts byErik Stakenborg

Hide

Wooting RGB SDK Guide

  • Introduction
  • RGB API description
  • Basic example with Node
  • Advanced example with Node

SDK's

  • Guide analog SDK
  • Guide RGB SDK

Useful links

  • About us
  • Wooting blog
  • Wooting one
  • Wooting two
Visit Us On FacebookVisit Us On TwitterVisit Us On InstagramVisit Us On Youtube

Want to submit a creation you made using one of our API’s? Hop on over to our Discord and let us know what you made.

  • contest
  • Vote now!
  • Wooting dev portal