Changing amixer volume with mouse buttons

Posted on 2011/07/12

3


I have a multi-button mouse (the Trust MI-2950R) with left and right wheel tilt, back and forward thumb buttons and a couple zoom buttons. I want to use them efficiently, and in my case, since I rarely use the horizontal scrolling, I wanted to map on the left-right wheel tilt another function that I use often: changing the volume of the audio.

Trust Optical Mouse MI-2950R

Trust Optical Mouse MI-2950R

Since I’m using Debian with XFCE, the audio is managed by amixer. It is possible to change the volume from the command line, first of all I got a list of possible “controls” to adjust:

$ amixer scontrols
Simple mixer control 'Master',0
Simple mixer control 'Headphone',0
Simple mixer control 'PCM',0
Simple mixer control 'Front',0
...

Then I run “amixer set Master 10%+” and noticed that the volume was raised, and a notification pop-up was flashed by the desktop environment. In order to map this command to a mouse button I used xbindkeys. First I needed to know what identifier is mapped on the left-right tilt buttons. For this, the “xev” command is very useful: it shows a small window that captures mouse and keyboard events, and dumps the debug output on the console. By tilting the wheel on the left, this output is shown among many lines:

...
ButtonPress event, serial 34, synthetic NO, window 0x2a00001,
root 0x164, subw 0x2a00002, time 9499114, (46,17), root:(597,433),
state 0x10, button 6, same_screen YES
...

It means that the left tilt button is mapped as button 6. In the same way I discovered that the right tilt button is mapped as button 7. I then installed xbindkeys, created a  “~/.xbindkeysrc” file and added the following configuration:

...
#Mouse Volume Up
"/usr/bin/amixer set Master 10%+"
m:0x0 + b:7

#Mouse Volume Down
"/usr/bin/amixer set Master 10%-"
m:0x0 + b:6

xbindkeys runs when the graphical environment shows up, and it reads my configuration files. Now when the button 6 or 7 is pressed, the event is captured by xbindkeys which runs the commands to raise and lower volume.

Posted in: Software