Rudimentary ioHook replacement written in Rust for Node.
You can use the Build-Free Package npm i @tcardlab/rshook
(Win/Mac only).
Otherwise, you can build it yourself (See below for details).
NOTE: First argument sent to callback is for errors. Structure callback arguments like so:
function callback (error, ...event) { console.log(event) }
You have to build this one yourself (See below for details).
You have to build this one yourself (See branch for details). This was prompted by issue #1. You can read more about the reasoning there.
You may import it as "node module" from github:
- Napi:
npm i https://github.com/tcardlab/rsHook/tarball/napi-rs
- Bindgen:
npm i https://github.com/tcardlab/rsHook/tarball/node-bindgen
Then, add the following script to package.json
to build with npm run build-rs
:
{
"scripts": {
"build-rs": "cd node_modules/@tcardlab/rshook && npm run build"
} // If this fails, you may need a cli tool. See relevant branch for info.
}
Otherwise, you may download/clone the repo via github and follow the relevant branch instructions.
I have not tested linux nor been able to build it, so you are on your own.
These packages depend heavily upon the rdev crate. So, you may have to look there for info and trouble shooting. Their github CI implies libxtst-dev
and libevdev-dev
are dependencies.
Because it was easy, rsHook returns an array of strings [eventType, scanCode, timestamp, inputName]
Example:
[ 'keyup', '37', '1648357401244', 'KeyK' ]
[ 'mousedown', '0', '1648357399405', 'Left' ]
If you want to create a simple wrapper to match ioHook:
const { rsHook: ogHook } = require('@tcardlab/rshook')
function rsHook (callback) {
//const wrapper = (ogEvent) { // Node-Bindgen
const wrapper = (Error, ...ogEvent) => { // Napi-RS
let ioHookEvent = {
type: ogEvent[0],
[e[0].includes('key') ? 'keycode' : 'button']: +e[1]
// etc.
}
callback(ioHookEvent)
}
ogHook(wrapper)
}
General
- Pass mouse location
- ioHook parity
- Open-Trade/rdev fork has some interesting work
- Use
@rsHook/napi
and@rsHook/bindgen
org-scoping - Consider run-on-arch-action for CI
- Fix mac
calling TIS/TSM in non-main thread
. solution? - A termination feature (could cancel thread, but macs don't like running it in thread... so maybe process::exit(1) or test if panic works)
Node-Bindgen
- CI for mac, win, and linux
- Tests
Napi-rs
- CI Linux builds
- Tests
Neon
- I was unsuccessful in getting this working (lifetime and mut/static conflicts between neon context and rdev callback). If you figure it out, make a pr, I'd love to see it!