Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/colecrouter/wooting-js
Minimal JavaScript (TypeScript) library using WebHID
https://github.com/colecrouter/wooting-js
javascript typescript wooting-keyboard
Last synced: 5 days ago
JSON representation
Minimal JavaScript (TypeScript) library using WebHID
- Host: GitHub
- URL: https://github.com/colecrouter/wooting-js
- Owner: colecrouter
- License: unlicense
- Created: 2021-07-27T01:57:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-22T21:34:43.000Z (over 2 years ago)
- Last Synced: 2024-11-02T18:02:39.383Z (17 days ago)
- Topics: javascript, typescript, wooting-keyboard
- Language: TypeScript
- Homepage: https://mexican-man.github.io/wooting-js/
- Size: 53.7 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wooting-js
Lightweight JavaScript (TypeScript) library using WebHID. Just for reading analog values, not for RGB.## Demo
[Click here](https://mexican-man.github.io/wooting-js/)## How to use
First you have to make sure the client's [browser supports WebHID](https://caniuse.com/webhid). You can check this like so:
```js
if ("hid" in navigator) {
// Good 👍
} else {
// Bad 💀
}
```Install the script:
```bash
npm i wooting-js
```Import, then trigger the prompt to get a keyboard (has to be user triggered):
```js
const keyboards = await ConnectNew();
```Set up a promise waiting for the user to pick their Wooting keyboard:
```js
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:
1. Through a listener
2. Through the buffer#### Listener:
```ts
kb.device.addEventListener('akeydown', (event) => {
const { key, value } = event.detail;
console.log(`${key} key value: ${value}`);
})
```#### Buffer:
```ts
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.` to get the id for each key.