Skip to content

polyvariant/macropad4s

Repository files navigation

Macropad4s

A Scala Native application for intercepting and handling input events from programmable macro keyboards.

This project demonstrates how to use Scala Native to directly interact with Linux input devices at a low level, enabling custom keyboard shortcuts and device control without relying on proprietary manufacturer software.

Project Structure

This is a multi-module SBT project with the following structure:

  • core - Core functionality for grabbing macropad events as fs2 stream
  • framework - Framework that allows you to build your own macropad app
  • app - demo application showing how you can utilize the framework

Building

# Build the native executable first
sbt app/nativeLink

# Run the built executable
./modules/app/target/scala-3.3.7/app

# Run with specific device path
./modules/app/target/scala-3.3.7/app --device /dev/input/event0

Features

  • Direct Linux input device access using Scala Native and ioctl system calls
  • Functional programming approach with Cats Effect and FS2
  • Event-driven keyboard handling with exclusive device access
  • Support for custom key actions
  • Secure alternative to proprietary manufacturer software

How It Works

The application:

  1. Opens a specified input device path (e.g., /dev/input/event11)
  2. Uses EVIOCGRAB ioctl to grab the device exclusively, preventing other programs from receiving input events
  3. Processes input events in a streaming fashion using FS2
  4. Performs custom actions based on key presses (e.g. volume control)

Device Detection

To find your specific input device, you can use:

# Find your device by vendor and product ID
VENDOR="514c"; PRODUCT="8851"; for ev in /dev/input/event*; do udevadm info -q property -n "$ev" | grep -q "ID_VENDOR_ID=${VENDOR}" && udevadm info -q property -n "$ev" | grep -q "ID_MODEL_ID=${PRODUCT}" && echo "$ev"; done

You can also just run the app providing vendor and product as arguments:

./modules/app/target/scala-3.3.7/app 514c 8851

About

Scala lib and cli tool for macropad hotkeys

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published