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.
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
# 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- 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
The application:
- Opens a specified input device path (e.g.,
/dev/input/event11) - Uses
EVIOCGRABioctl to grab the device exclusively, preventing other programs from receiving input events - Processes input events in a streaming fashion using FS2
- Performs custom actions based on key presses (e.g. volume control)
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"; doneYou can also just run the app providing vendor and product as arguments:
./modules/app/target/scala-3.3.7/app 514c 8851