-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: expose Xkeys.filterDevice() static method, used to filter for co…
…mpatible X-keys devices when manually handling HID devices
- Loading branch information
Showing
6 changed files
with
89 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const HID = require('node-hid') | ||
const { setupXkeysPanel, XKeys } = require('xkeys') | ||
|
||
/* | ||
This example shows how to use node-hid to list all connected usb devices, then | ||
connecting to any supported X-keys panels. | ||
*/ | ||
|
||
Promise.resolve().then(async () => { | ||
|
||
// List all connected usb devices: | ||
const devices = await HID.devicesAsync() | ||
|
||
for (const device of devices) { | ||
|
||
// Filter for supported X-keys devices: | ||
if (XKeys.filterDevice(device)) { | ||
|
||
console.log('Connecting to X-keys device:', device.product) | ||
|
||
setupXkeysPanel(device) | ||
.then((xkeysPanel) => { | ||
xkeysPanel.on('disconnected', () => { | ||
console.log(`X-keys panel of type ${xkeysPanel.info.name} was disconnected`) | ||
// Clean up stuff | ||
xkeysPanel.removeAllListeners() | ||
}) | ||
xkeysPanel.on('error', (...errs) => { | ||
console.log('X-keys error:', ...errs) | ||
}) | ||
|
||
xkeysPanel.on('down', (keyIndex, metadata) => { | ||
console.log('Button pressed', keyIndex, metadata) | ||
}) | ||
|
||
// ... | ||
}) | ||
.catch(console.log) // Handle error | ||
|
||
} else { | ||
// is not an X-keys device | ||
console.log('Not a supported X-keys device:', device.product || device.productId) | ||
} | ||
|
||
} | ||
|
||
}).catch(console.log) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters