Skip to content

tcardlab/rsHook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

rsHook

Rudimentary ioHook replacement written in Rust for Node.

Two Implementations:

Napi-RS Version:

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) }

Node-Bindgen Version:

You have to build this one yourself (See below for details).

Spawn Version:

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.


Building rsHook Yourself:

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.


Linux:

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.


Output Parity:

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)
  }

To-Do:

General

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!