wooting-js
v0.0.3
Published
JS library for reading analog data from a Wooting keyboard using WebHID.
Downloads
3
Readme
wooting-js
Lightweight JavaScript (TypeScript) library using WebHID. Just for reading analog values, not for RGB.
Demo
How to use
First you have to make sure the client's browser supports WebHID. You can check this like so:
if ("hid" in navigator) {
// Good 👍
} else {
// Bad 💀
}
Install the script:
npm i wooting-js
Import, then trigger the prompt to get a keyboard (has to be user triggered):
const keyboards = await ConnectNew();
Set up a promise waiting for the user to pick their Wooting keyboard:
k.then((res) => {
const kb = res[0]
// kb is our keyboard!!!
}).catch((err) => {
// catch error
});
And you're all set! There are two ways to capture user input:
- Through a listener
- Through the buffer
Listener:
kb.device.addEventListener('akeydown', (event) => {
const { key, value } = event.detail;
console.log(`${key} key value: ${value}`);
})
Buffer:
import { AnalogKeyCode } from 'wooting-js';
const p = kb.buffer[AnalogKeyCode.A];
console.log(`A key value: ${p}`);
Using a listener gives a smaller footprint, while reading the buffer is a lot more efficient for reading lots of keys. Pick whichever works best for you. In both cases, the value returned is from 0-255. Use AnalogKeyCode.<insert-key-name>
to get the id for each key.