KDE Tip: Binding mouse buttons to keyboard shortcuts
By Niels on .
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 /usr/bin/xte /usr/bin/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'"
b:9
# Bind "forward" mouse button to CTRL+F9
"xte 'keydown Control_L' 'key F9' 'keyup Control_L'"
b:8
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.
Source
http://marian.schedenig.name/2012/06/07/mapping-kde-actions-to-extra-mouse-buttons/