macOS – How to Monitor Signals from an HID Device

macosmojave

There is a way in the mac world to monitor all the signals an HID device (a remote) sends to the OS?
The final aim is to handle those and remap them to keyboard shortcuts.

More details: a Logitech remote I have (Logitech S510 media remote, a combo keyboard/mouse/remote) doesn't works on macOS (just the volume controls and few other buttons works). I was wondering if there is an easy way (in any language) to listen the remote signals and remap them.
So the first step is to find a way to monitor the signals and check if all buttons signals are recognized by the OS.

Best Answer

NSEvent

To monitor input events sent to macOS from Human Interface Devices (HID), look at NSEvent's addGlobalMonitorForEventsMatchingMask:handler:. This is the method used to associate scripts and tasks to hotkeys by third party macOS tools.

You will likely need to write in Objective-C or Swift and codesign the resulting binary. I expect you will also need to grant the binary additional access rights at runtime – probably in the Accessibility panel of System Preferences > Security & Privacy.

A search on GitHub will provide a few sample projects using this method.