Skip to content

Instantly share code, notes, and snippets.

@modellking
Last active May 14, 2025 19:21
Show Gist options
  • Save modellking/b315f51c706c27b9a3e6459cd7a42e5f to your computer and use it in GitHub Desktop.
Save modellking/b315f51c706c27b9a3e6459cd7a42e5f to your computer and use it in GitHub Desktop.
Linux MIDI to virtual keyboard with ydotool

Using ydotool and systemd we can set this up

Install ydotool

sudo dnf install ydotool
sudo apt install ydotool

Replace MIDI Commands and Keycodes (from /usr/include/linux/input-event-codes.h)

Example maps CC42 to F14

After writing the files, you can register and start the services

systemctl daemon-reload
systemctl enable ydotool midiKeyboardBridge
systemctl start ydotool midiKeyboardBridge
[Unit]
Description=midi to ydotool Bridge
[Service]
ExecStart=/bin/bash /home/user/scripts/midiKeyboardBridge
Restart=Always
ExecStartPre=/bin/sleep 2
TimeoutSec=180
TimeoutStartSec=0
[Install]
WantedBy=default.target
[Unit]
Description=ydotool Deamon
[Service]
ExecStart=ydotoold -P 666 -p /tmp/.ydotool_socket
Restart=Always
User=root
ExecStartPre=/bin/sleep 2
TimeoutSec=180
[Install]
WantedBy=default.target
#!/bin/bash
aseqdump -p "X-TOUCH COMPACT" | \
while IFS=" ," read src ev1 ev2 ch label1 data1 label2 data2 rest; do
case "$ev1 $ev2 $data1 $data2" in
"Control change 42 127" ) ydotool key 184:1 ;;
"Control change 42 0" ) ydotool key 184:0 ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment