I have something like this in linux using a novation launchcontrol, it's quite straightforward using aseqdump, say I use the buttons to switch desktops, I have this launched as part of my session and always in background. While developing this I just printed $line to see what aseqdump sent to figure out the regexes
while IFS=' ' read -r line; do
if [[ "$line" == *"client"*"Launch Control"\* ]]; then
device=$(echo "$line" | cut -d' ' -f2)
fi
done < <(aconnect -i)
aseqdump -p ${device::-1} | while IFS=' ' read -r line; do
if [[ "$line" == *"Note on"* ]]; then
note=$(echo "$line" | grep -o "note [0-9]*" | cut -d' ' -f2)
if [ "$note" == "9" ]; then
wmctrl -s 8
fi
elif [[ "$line" == *"Control change"*"127" ]]; then
note=$(echo "$line" | grep -o "controller [0-9]*" | cut -d' ' -f2)
if [ "$note" == "114" ]; then
# some macro
fi
fi
done