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 🙏

© 2025 – Pkg Stats / Ryan Hefner

evdev-gamepad

v0.1.3

Published

A wrapper on an evdev file to allow easy setup / reading of events

Readme

Event Device Gamepad

Receive events for gamepad-like devices using evdev files. Deals with:

  • Input parsing
  • Normalisation
  • Reconnection handling
  • Input state tracking
  • Watching for Macros

Does NOT deal with:

  • Device discovery
  • Bluetooth pairing
  • Device Identification
  • Gamepad inputs (LEDs, Rumbles, FF etc.)

Usage

Device is the main class, it is an extension of EventEmitter and emits the following events:

  • state-change - When an input state changes
  • macro - When a macro is triggered
  • connect - When a device is being read and events should be received
  • disconnect - When a device is no longer being read and events should not be received
  • raw-input - On any EVDev event, passing the parsed evdev event. Useful for new mappings and debugging.

Quick start

Output parsed events from a device. ./samples/basic.js

import { Device } from 'evdev-gamepad';

const device = new Device({
  // Change this to your /dev/input/ device
  path: "test_data/face_buttons.bin",
});

device.on('state-change', (state) => {
  console.log('[INPUT]', state.input, state.state)
  // Outputs `[INPUT] LeftBumper Pressed`
});

// `await` is optional here
await device.connect();

Lifecycle

The Device class doesn't care if the underlying device is available or not. It uses fs.watch (chokidar) under the hood to wait till it appears. If it goes away it will wait again.

This means you can keep the same instance of the class and event callbacks as long as you like. If the device is disconnected and reconnected it will automatically start emitting events again.

A connect event is emitted when the device is ready to be read and a disconnect event is emitted when the device is no longer available.

Macros

Receive an event when a series of buttons are pressed:

import { Device, Input, State } from '../dist/index.js';

const device = new Device({
  // Change this to /dev/input/event{X} for your device
  path: "test_data/macro_easy.bin"
});

device.on('state-change', (state) => {
  console.log('[INPUT]', state.input, state.state) // LeftBumper Pressed
});

// ./types:MacroConfig
// Macros can be defined at any point, whether the device is connected or not
device.macros["shoulders"] = {
  inputs: [{
    input: Input.RightBumper,
    state: State.Pressed,
  }, {
    input: Input.LeftBumper,
    state: State.Pressed,
  }],
  exclusive: true,
  someRandomOtherDataToPass: 42
}

// All macros fire the same event, use the ID to differentiate
device.on('macro', (id, macro) => {
  console.log('[MACRO]', id, macro.someRandomOtherDataToPass)
  // Outputs: `shoulders 42`
});

// `await` is optional here
await device.connect();

Mapping

The default BaseMapping is setup for an Xbox Series S controller.

Included is a mapping for PS5Controller and SwitchProController which can be used by passing the mapping to the Device constructor.

import { Device, Mappings } from 'evdev-gamepad';

const device = new Device({
  path: "test_data/face_buttons.bin",
  mapping: new Mappings.SwitchProMapping()
});

device.connect();

You can build your own mappings at the base level by implementing the MappingClass interface. There is only one function mapEvent that takes an EVDev "struct" and needs to return an Input and State (an array of them, in case of multiple inputs or sync event handling).

To help creating a mapping, use EchoMapping which will simply console log the evdev codes for anything you press.

Motion controls / touch pads etc.

This library is organised around "Devices" as EVDev files because that's how controllers are represented in linux, this has some side effects like a PS5 controller is technically 3 devices, one for the traditional buttons and sticks, one for the touchpad and one for the motion controls.

To take input from all 3 you need to create 3 Devices so unfortunately macro's can't cross those boundaries.

LEDs and Rumbles and Force Feedback

There is also no support for talking back to the controller. This library is intentionally simple and light weight. There's some simple ways to affect Rumble and LEDs but they quickly spiral in complexity and require whole drivers. These drivers already exist for a lot of controllers, use those instead.

  • https://github.com/atar-axis/xpadneo
  • https://github.com/nowrep/dualsensectl

Development

This library is in use in my home project controlling a raspberry pi with my game controllers and using steamlink. It's not perfect but it's good enough for me. If you have any issues or suggestions please open an issue or PR.