node input watcher
Find a file
2022-03-24 14:01:46 +01:00
.vscode added possibility to spawn commands with sudo, optimized some stuff 2022-03-10 12:29:41 +01:00
libs fixed location of '.nvmrc' 2022-03-11 17:00:28 +01:00
.gitignore renamed 'config.json' to 'example_config.json' and updated '.gitignore' 2022-03-24 10:54:43 +01:00
.nvmrc fixed location of '.nvmrc' 2022-03-11 17:00:28 +01:00
example_config.json renamed example config file 2022-03-24 14:01:46 +01:00
LICENSE.md added license 2022-03-24 10:54:29 +01:00
ninwa.js added possibility to spawn commands with sudo, optimized some stuff 2022-03-10 12:29:41 +01:00
ninwa.service added 'sudo' functionality and partially fixed combos 2022-03-10 17:06:44 +01:00
package.json added possibility to spawn commands with sudo, optimized some stuff 2022-03-10 12:29:41 +01:00
README.md updated readme 2022-03-24 10:36:23 +01:00

ninwa

node input watcher

requirements

  • evtest
  • node.js
  • nvm

setup (as root)

  • install nvm

  • to load nvm restart your terminal or source ~/.nvm/nvm.sh

  • clone the project (to '/opt/ninwa')
    git clone https://git.velvettear.de/velvettear/ninwa.git /opt/ninwa

  • install and switch to a supported node.js version (automatically done via .nvmrc file) nvm install

  • install the required modules
    npm install

  • switch back to your system's default node.js version nvm deactivate

  • execute ninwa
    nvm run ninwa.js

systemd

for security reasons it is highly recommended to not run ninwa with root permissions!

  • create a new system user
    useradd -U -r -s /usr/bin/nologin node

  • make your install of nvm available to the new user
    cp -R ~/.nvm /opt/nvm
    chown -R node /opt/nvm

  • symlink the provided systemd-service file and modify it according to your needs
    ln -s /opt/ninwa/ninwa.service /etc/systemd/system/ninwa.service

  • reload systemd-services
    systemctl daemon-reload

  • enable and start the ninwa as a systemd-service
    systemctl enable --now ninwa

configuration

configuration is done entirely within the file config.json.

log: [object]

  • level: [string] verbosity of the log; either debug, info, warning or error
  • timestamp: [string] format string for the timestamp; review moment.js for further information

combos: [object]

  • delay: [number] time in milliseconds until a combo will be reset

watchers: [object-array]

  • device: [string] name of or path to an input device; ninwa automatically tries to locate the device in /dev/input and /dev/input/by-id/ if only a name is given
  • restart: [boolean] restart watcher on close
  • sudo: [boolean] use sudo to start the evtest process
  • keys: [object-array]
    • key: [string] name of the key
    • combo: [string-array] name of one or more keys (in order)
    • event: [string] event type to filter evtest's output for
    • type: [string] type of the key event; either keyup, keydown or keyhold
    • delay: [number] time in milliseconds until the key will be registered again (mostly useful for keyhold-events; unavailable for combos)
    • command: [string] name of the command to execute on key press / combo end

commands: [object]

  • name: [object]
    • cmd: [string] command / path to script to execute
    • args: [string-array] arguments to pass to the executed command
    • sudo: [boolean] use sudo to execute the command

note:
if you intend to use ninwa as a systemd-service with sudo make sure the configured user is allowed to execute the command without entering a password. otherwise your service will just stop at the password prompt!

  • sudo visudo
  • username ALL=(ALL) NOPASSWD: command