xorg.conf files tend to be a pain. You can go ahead and edit it if you want, but, personally, I would not.
There's a commandline tool called xbindkeys
. It allows you to route specific button presses to commands. There's a full explanation here, but I will try to explain it briefly here.
Firstly, if you want to bind the keys to actions, you need to set up keyboard shortcuts for them (Settings > Keyboard > Shortcuts). You do not need to do this to launch programs.
You'll need to install xbindkeys
and xautomation
.
sudo apt-get install xbindkeys xautomation
Then, open a terminal (Ctrl+Alt+T) and run the xev
command. It should pop up a small little window with a white box and a black background. Try not to move the mouse (it will make things hard to find), and click the button you want to set up. Then, go back to the terminal and find the last ButtonPress
and/or ButtonRelease
events (either one). The event will give you a number for the button you pressed (button <number>
, towards the end). Remember that number.
Now, in a new terminal instance, do nano ~/.xbindkeysrc
. This will create a text file by which you can configure xbindkeys
.
For that key, create an entry like so:
"command"
b: <button number>
For example, say you wanted to open Firefox when you pressed the mouse's "home" button (for me, button 10):
# Run Firefox when "home" pressed
"firefox"
b: 10
Or, if you wanted to bind it to a desktop action (like minimize all windows, like shown below), you would tell it to simulate the keybinding with xte
:
# Minimize all windows on "2" button press
"xte 'keydown Control_L' 'keydown Alt_L' 'key D' 'keyup Alt_L' 'keyup Control_L'"
b: 11
You would repeat this process for the other buttons.
When you're done, save the file (Ctrl+O and Enter), and close nano
(Ctrl+X).
Then, just launch xbindkeys
outside the terminal (Alt+F2, then type xbindkeys
).
However, you will want it to autolaunch after every shutdown. Add it to your autostart configuration (Settings > Session > Startup > Application Autostart, add xbindkeys
).