Giter Club home page Giter Club logo

hid-event-processor's Introduction

HID Event Processor (HEP)

This is a simple event processor for HID devices (e.g. USB keyboards or headsets) which allows to run a command when a key (e.g. multimedia key or headset button) is pressed.

Motivation

I got the Bose 700 for free with my new phone but unfortunately the headphones, when connected directly via Bluetooth, don't have any way how I can mute the mic when on a conference call (e.g. Zoom, Teams, Google Chat). So I bought the Bose USB Link that should solve this problem. Unfortunately the muting (long-press on the right hand side ear cup) didn't work out of the box and required to remap the KEY_MICMUTE key to F20 key. That was simply done using UDEV:

sudo cat <<END > /etc/udev/hwdb.d/99-bose.hwdb`
evdev:input:b0003v05a7pa310*
 KEYBOARD_KEY_b002f=f20
 KEYBOARD_KEY_ff990004=f20
END
sudo systemd-hwdb update
sudo udevadm trigger

Unfortunately this way it didn't visually nor acoustically indicate if the mic is muted or unmuted. That's why I have decided to write HEP which allows to run a script on any event from the headphones without the need to remap any keys.

The script can mute/unmute the mic and change the light color on the Bose USB Link (that makes the headphones to play a sound) using system tools like evtest, pactl and evemu-event.

Installation

Python packages

HEP requires some non-standard packages. Those can be installed by using pip (the requirements.txt file can be found in the HEP Git repository):

pip install -r requirements.txt

On Arch Linux it can be installed using system packages:

pacman -S python-evdev python-yaml

Using per-user Systemd instance

This requires Systemd instance running under a user.

The HEP can be installed like this:

cd ~/
git clone https://github.com/jtyr/hid-event-processor.git
mkdir -p ~/.config/systemd/user/
ln -s ~/hid-event-processor/systemd/hep.service ~/.config/systemd/user/
cat <<END > ~/.config/systemd/hep.conf
HEP_PATH=~/hid-event-processor/hep.py
END
systemd --user enable hep
systemd --user start hep

Ad-hoc from command line

cd ~/
git clone https://github.com/jtyr/hid-event-processor.git
cd hid-event-processor
./hep.py

Configuration

Configuration is done by creating a YAML file that contains definition which devices and keys should be monitored and what command to execute when the event appears:

# Configuration for the "Logitech Pro Gaming Keyboard"
- device:
    # Device identification
    vendor: 0x46d
    product: 0xc339
    version: 0x111
  keys:
    # Play/Pause key down
    - type: 1
      code: 164
      value: 1
      # Simple command to run
      command: kcalc
      # Run on background
      background: true
    # FastForward key down
    - type: 1
      code: 163
      value: 1
      # Simple command to run
      command: drawio
      # Run on background
      background: true

# Configuration for the "Bose 700 ACM Headphones"
- device:
    # Device identification
    vendor: 0x5a7
    product: 0xa310
    version: 0x111
  keys:
    # MSC_SCAN on KEY_MICMUTE longpress
    - type: 4
      code: 4
      value: b002f
      # Multi-argument command to run
      command:
        - ~/bin/bose.sh
        - toggle
        # Use the actual device path as one of the command parameters
        - "{{ device.path }}"
    # MSC_SCAN on BTN_0 press
    - type: 4
      code: 4
      value: ff990004
      # Multi-argument command to run
      command:
        - ~/bin/bose.sh
        - toggle
        # Find a device that has the specivied capability (17=EV_LED, 7=LED_MUTE)
        - "{{ device[cap=17,subcap=7].path }}"
    # MSC_SCAN on KEY_PLAY (hangup)
    - type: 4
      code: 4
      value: c00b0
      # Multi-argument command to run
      command:
        - ~/bin/bose.sh
        - hangup
        # Find a device that has the specivied capability (17=EV_LED, 7=LED_MUTE)
        - "{{ device[cap=17,subcap=7].path }}"

The device and key details can be found by using evtest tool.

Author

Jiri Tyr

License

MIT

hid-event-processor's People

Contributors

jtyr avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.