Binding mouse buttons to keyboard shortcuts

You can use xbindkeys and xte to map custom mouse buttons to keyboard shortcuts, which KDE can pick up and leverage anywhere. Using this trick you can have Ctrl + C and Ctrl + V fired by pressing your 4th and 5th mouse buttons, or for instance firing the desktop grid and present windows effects.

As you will need the xte and xbindkeys commands on your system installed in order for this to work, you will have to check whether you have the commands. On Debian derivatives you can install them with sudo apt-get install xbindkeys xautomation, and verify they are on your system with:

$ which xte xbindkeys

Now, create a default configuration file for xbindkeys:

xbindkeys --defaults > ?/.xbindkeysrc

Then edit this file to add xte calls for your keyboard shorcuts and bind them to mouse buttons. The xbindkeys utility will pick up your mouse button clicks in the background and emulate key presses using xte. For example, the following lines will map mouse button 8 to Ctrl+F9 and mouse button 9 to Ctrl + F8:

# Bind "back" mouse button to Ctrl+F8
"xte 'keydown Control_L' 'key F8' 'keyup Control_L'"

# Bind "forward" mouse button to Ctrl+F9
"xte 'keydown Control_L' 'key F9' 'keyup Control_L'"

To make xbindkeys re-read the configuration file without restarting the X server, simply execute this:

killall xbindkeys && xbindkeys

Now you can simply bind applications and other actions to the shortcuts you just defined.