This library provides a driver for reading XBOX 360 Chatpad serial data in NodeJS. It also maps th chatpad key codes to ASCII values where possible.
npm i chatpad
const Chatpad = require('..');
(async() => {
const pad = new Chatpad('/dev/ttyUSB0');
await pad.open();
pad.on('key', (keys) => {
console.log('key', keys);
});
pad.on('modifier', (keys) => {
console.log('modifier', keys);
});
pad.on('error', (err) => {
console.log('error', err);
});
})();
Constructor, pass the serial port location into here. Should work with Windows serial ports too.
Used to open the serialport and initialise the regular message the library needs to send to the Chatpad.
Shuts down the timed tasks and closes the serial port.
Sets the event listener for the given event.
Sent out whenever a key state changes, excluding modifier keys. Eg:
{
raw: { key: 52, modifier: 0 },
pressed: true,
code: 'f',
caps: false,
modifier: undefined
}
The raw
object contains the raw key-code and modifier values from the Chatpad. caps
is tracked by the driver and automatically toggled when the 'Caps' button is pressed. For possible modifier and code values see map.js
.
Send out whenever the state of a modifier key changes.
{
raw: 4,
pressed: true,
modifier: 'orange'
}
Raw is the raw modifier byte value. For a list of possible modifier values see map.js
.
Error message that's sent out if an invalid packet is received. For most cases this can be ignored because the Chatpad sends packets multiple times to ward against corruption.
This work is inspired by Cliffle's: