ubuntu:mouse:mapping_mouse_buttons_to_arbitrary_functions
This is an old revision of the document!
Table of Contents
Ubuntu - Mouse - Mapping Mouse Buttons to Arbitrary Functions
Install xbindkeys
sudo apt install xbindkeys
NOTE: Xbindkeys is a program that allows to bind commands to certain keys or key combinations on the keyboard.
Install xautomation
sudo apt install xautomation
NOTE: This provides the xte component; to send events directly to the input handler.
- These events include Button presses and Mouse clicks.
Create the xbindkeys Configuration File
xbindkeys --defaults > $HOME/.xbindkeysrc
Edit the xbindkeys Configuration File
Edit ~/.xbindkeysrc.
- To create a double-click event when button 8 is released, add the following:
- ~/.xbindkeysrc
"/usr/bin/xte 'mouseclick 1' 'mouseclick 1' &" b:8 + Release
NOTE: The format of this file is a series of paired lines.
- The first line is a command to be executed for an event;
- The quotation marks (“”) around the command is required.
- The second line is the event description.
- The first mouse button (left) is called b:1, the second (right) b:2 and so forth.
Here, the xte component of xautomation to send events directly to the input handler.
Additional xbindkeys Configurations
Here are some examples of additional entries.
- ~/.xbindkeysrc
# Back changed to Copy "xte 'keydown Control_L' 'key C' 'keyup Control_L'" b:8 # Forward "xte 'keydown Alt_L' 'key Right' 'keyup Alt_L'" b:9
NOTE: This maps:
- Back button: 8
- When Button 8 on the mouse is pressed, send a CTRL-C followed by a Key up.
- Forward button: 9
- When Button 9 on the mouse is pressed, send a ALT followed by a Key up.
Run at startup
One approach is to create a shell script that performs the Mouse Button mapping:
echo "xinput --set-button-map 21 3 2 1" > leftmouseremap.sh
Give it executable permission:
chmod +x leftmouseremap.sh
NOTE: Either run the script manually, or configure it to automatically run on system reboot.
- Follow any process to have this script run at boot if needed.
- Remember to configure 'xbindkeys' to run automatically on system startup too if needed:
- '/usr/bin/xbindkeys'
References
ubuntu/mouse/mapping_mouse_buttons_to_arbitrary_functions.1635176079.txt.gz · Last modified: 2021/10/25 15:34 by peter