The large majority of Laptops and modern keyboards come with volume controls, so lets put them to use. If you have been following my Arch Linux/DWM guides you should have alsa setup and functioning, but without a convenient way to control the volume. Xbindkeys makes it pretty easy to get your multimedia keys (or any key combination) into a usable state without the help of GUI tools.
First off, lets get xbindkeys
$ sudo pacman -S xbindkeys
You can get a default configuration file with:
$ xbindkeys --defaults > ~/.xbindkeysrc
or remove “
> ~./xinbindkeysrc” to view the format we will be using. I prefer to just start from scratch so my config isn’t all cluttered up by examples.
$ touch ~/.xbindkeysrc
Next we need to get our key bindings. Running this command will open a blank window. When it pops up, hit the key or combination of keys you want to associate with a function. I start with the decrease volume button. In return you will be greeted with the binding.
m:0x0 + c:169
Copy these lines into ~/.xbindkeysrc and edit. Scheme function will be replaced with the line you want to execute. You only need one of the last two lines to get this to work. Repeat these steps for every button you want to bind.
# Decrease Volume on DAC and DAC 1
"/usr/bin/amixer -q sset DAC 2-"
"/usr/bin/amixer -q sset 'DAC,1' 2-"
# Raise Volume on DAC and DAC 1
"/usr/bin/amixer -q sset DAC 2+"
"/usr/bin/amixer -q sset 'DAC,1' 2+"
I am running a ICE1712 chipset set (MAudio24/96) so I had to bind keys twice, one for each audio channel to get my setup working properly. As you can see the first line is the command executed and the second is the function. Comments are prefixed with ‘#.’ Replace DAC with PCM or Master. Open alsamixer from term to view which channel you should be controlling.
Edit your .xinitrc file and put xbindkeys above your WM line so it will launch first.
$ vim ~.xinitrc
Kill Xorg and log back in. Launch alsamixer once more, and test out your new key bindings. Pretty convenient, eh?