Access USB HID devices from Raycast
npm install raycast-hidAccess USB HID devices from Raycast
Due to the problem of Raycast building extension, you need to manually copy HID prebuilds to your extension folder. Also, Raycast only allows attachments to be placed in the assets directory.
However, node-hid can only find driver files in its own directory. This package prepares a set of methods to facilitate your HID-related development in Raycast.
``shell`
npm i raycast-hid
Run npx raycast-hid-setup under your extension project directory to setup HID prebuilds to the assets folder.
Remember to run preparePrebuilds() before you use any function from the HID.
`tsx
import { useEffect, useState } from "react";
import { List } from "@raycast/api";
import { HID, preparePrebuilds } from "raycast-hid";
export default function Command() {
const [isLoading, setIsLoading] = useState(true);
const loadPrebuilds = async () => {
await preparePrebuilds();
setIsLoading(false);
console.log(HID.devices());
};
useEffect(() => {
loadPrebuilds();
}, []);
return ;
}
`
This function programmatically copies the prebuilds files from assets/prebuilds to the correct directory for node-hid.
This exposes all node-hid functions. For example:
`typescript
import { HID } from "raycast-hid";
console.log(HID.devices());
``
- node-hid - Access USB & Bluetooth HID devices through Node.js
MIT