I wasn’t able to easily found a solution for sending terminal commands/control Volumio with keyboard. Most of the solutions that you will find will always require you to run a Gui. And since you shouldn’t need one to run with Volumio I come up with this simple solution.
Long history short about my project:
Since among other things I have 17 buttons and 5 rotary encoders I had to do something different to avoid lacking GPIO pins. So I’ve connected everything to an Adafruit Pro Trinket. The code on the Trinket will detect button press or rotary encoder rotation and will send the correspondent keypress to Pi via the USB connection. The Pi will receive the keypress as a normal Keyboard input and will run the triggerhappy command for that key.
Later on I can make a post with all the information about this solution, but right now and since I didn’t find any tutorial I just want to share how to use your keyboard to play, pause, mute, etc on your volumio build.
Now the solution!
First we need to install triggerhappy:
sudo apt-get install triggerhappy
Then we need to assign terminal commands to keys. We do that by editing triggerhappy config file:
sudo nano /etc/triggerhappy/triggers.d/audio.conf
This is just an example of a config file with some possibilites:
KEY_VOLUMEUP 0 mpc volume +1
KEY_VOLUMEDOWN 0 mpc volume -1
KEY_MIN_INTERESTING 0 mpc volume 0
KEY_PLAYPAUSE 0 mpc play
KEY_STOPCD 0 volumio stop
KEY_F1 0 mpc clear; mpc add http://analogbubblebath.housejunkie.ca:8000/deepershades; mpc play
KEY_F2 0 mpc clear; mpc add http://7719.live.streamtheworld.com:3690/OCEANPACIFIC_SC; mpc play
KEY_F3 0 mpc clear; mpc add mms://195.245.168.21/antena3; mpc play
KEY_F4 0 mpc clear; mpc add mmsh://emdirecto.tsf.pt/tsfdirecto?MSWMExt=.asf; mpc play
Every line of the config file should have three parameters:
[KEY_CODE] [WHEN] [COMMAND]
KEY_CODE: The code for the key
WHEN: 1 → pressing a key | 2 → holding a key | 0 → releasing a key
Last thing to do is to reload the config file:
sudo /etc/init.d/triggerhappy reload
To check if the config file is ok we should run:
sudo /etc/init.d/triggerhappy status -l
You can see which code represent every key by running the following command:
sudo thd --dump /dev/input/event0
More information about triggerhappy can be found on the github page:
https://github.com/wertarbyte/triggerhappy
PS: This was only tested with the last build of Volumio. As long as you can install triggerhappy it should work with every build.