npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shortcutd

v1.1.0

Published

Launch commands when pressing keys combinations

Downloads

11

Readme

shortcutd

Launch commands when pressing keys combinations. Key features:

  • Reads Kernel input device nodes directly so there is no need of any graphical environment and works whatever the launched software stack.

  • Support for blocking and non blocking commands spawns.

  • Resilient to keyboard hotplugs. You can plug your keyboard only when needed. There is no need for it to be plugged when shortcutd is launched.

shortcutd is a daemon written in NodeJS. It works on Linux and has been designed to execute low level/administrative commands like systemctl start some.service using keyboard shortcuts, on headless or embedded systems for example but is obviously not limited to.

Installation

$ npm install -g shortcutd

Configuration

shortcutd is configured via a JSON configuration file. Here is a simple working configuration file:

{
    "device": "/dev/input/by-id/usb-Logitech_USB_Keyboard-event-kbd",
    "shortcuts": [{
        "keys": "KEY_LEFTCTRL+KEY_LEFTALT+KEY_1",
        "blocking": true,
        "command": "echo Hello World!; sleep 5" 
    }, {
        "keys": "KEY_LEFTCTRL+KEY_LEFTALT+KEY_2",
        "blocking": false,
        "command": "echo Hello World!"
    }, {
        "keys": "KEY_LEFTCTRL+KEY_LEFTALT+KEY_2",
        "blocking": false,
        "release": true,
        "command": "echo key released"
    }]
}

Device node

The input device node path of the keyboard must be specified via the device property. Input device nodes are generaly located in /dev/input/. If you are not sure which device node corresponds to the keyboard you want to use — on some systems they are simply labeled event[0-9]+ — you can try them one by one by launching shortcutd in verbose mode and see if pressed keys are displayed to your terminal (see Usage below).

About (un|re)plug resilience: It is important for shortcutd to be able to detect your keyboard when (re)plugged that the device node has the same path. It is sometimes the case, like links inside the /dev/input/by-id subdirectory. If not, this can be configured nowadays on Linux systems through udev rules.

Device nodes are only readable by root by default. This can be configured with udev rules too.

Shortcuts configuration

Shortcuts are configured inside the shortcuts property. Each shortcut configuration object is defined by theses three properties:

keys

Define the keys combinations that will spawn the command when pressed. Each key code is separated by a + char. You can launch shortcutd in verbose mode without any shortcuts configured to print the codes of the keys in your terminal when they are pressed.

blocking

Tell shortcutd to wait (blocking) for the command to finish once spawned before allowing the user to spawn it again.

command

The command to spawn when the keys combinations are pressed

release

Specify the command to be triggered on key release instead of keypress.

Usage

$ shortcutd [-v] <config-file>

-v option enables verbose mode. Additionnaly to common verbose logs, every key press/release events are logged. This is especially useful to test device nodes and to get the name of the key codes.

shortcutd does not daemonize itself but can easily be launched as a systemd service. Simply put the following into a systemd service configuration file:

[Unit]
Description=Shortcutd

[Install]
WantedBy=multi-user.target

[Service]
ExecStart=/usr/bin/shortcutd /usr/local/etc/shortcutd.json

Known issues and improvments

  • shortcutd could be able to read input device events of others devices than keyboards (mouses, joysticks..) but only keyboard kernel event codes have been implemented.

  • Only english key mappings are supported. It means pressing a a char using an azerty keyboard is recorded as a q char. If key codes are configured as appearing in verbose mode this should not be an issue.

Contributions

... are welcome :)