Snippets Linux / Mouse Mapping

Mouse Mapping

By Marcelo Fernandes Jul 09, 2017

There are two basic ways to map a mouse and set a button to a different configuration In Linux.

The first one is a Simple Mouse Mapping, which consists of setting the function of a desired button to another mouse button function.
Situation: I want my thumb button to act as the scroll down button.

The second one is a Mapping via xbindkeys, which consists of setting the function of a desired button to another keyboard/mouse button function.
Situation: I want my thumb button to act as my keyboard space button.

Simple Mouse Mapping

Step 1 - Get the mouse ID via xinput:
First, we need to know which ID value corresponds
to the mouse that I want to map.


# Type in the following xinput command
xinput list

Answer:

# Note that there might be repeated Id's.
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ Gaming Keyboard                         	id=11	[slave  pointer  (2)]
⎜   ↳ E-Signal/A-One USB Gaming Mouse         	id=12	[slave  pointer  (2)]
⎜   ↳ E-Signal/A-One USB Gaming Mouse         	id=13	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ Power Button                            	id=6	[slave  keyboard (3)]
    ↳ Video Bus                               	id=7	[slave  keyboard (3)]
    ↳ Power Button                            	id=8	[slave  keyboard (3)]
    ↳ Sleep Button                            	id=9	[slave  keyboard (3)]
    ↳ Gaming Keyboard                         	id=10	[slave  keyboard (3)]
    ↳ Gaming Keyboard                         	id=14	[slave  keyboard (3)]
    ↳ E-Signal/A-One USB Gaming Mouse         	id=15	[slave  keyboard (3)]


Step 2 - Getting the buttons ID
After getting the mouse ID,
we need the buttons Id:

# Type the command and press the buttons that you want the id's.
# Remember to memorize those numbers.
xinput test 'mouse_id'

Step 3 - Mapping the buttons
Supposing that i want to map the buttons
8 and 9, which corresponds to the thumb buttons
in my configuration, to the scroll up and down buttons,
that corresponds to the buttons 5 and 4 in my configuration:

xinput set-button-map 'mouse_id' 1 2 3 4 5 6 7 5 4





Mouse Mapping Via xbindkeys

Step 1: Install dependencies

# Type in the commands:
sudo apt-get install xautomation
sudo apt-get install xbindkeys

Step 2: Retrieving the keys/buttons ID via xev.

# Get the keys / buttons that you want to change:
xev

Step 3: Create a xbindkeysrc file in the home directory with pre-loaded default config.

# It must be in home, and have the name ".xbindkeysrc"
xbindkeys --defaults > ~/.xbindkeysrc

Step 4: Modify this File with the desired mapping.

# Changes the mouse button 9 to Page Up and 8 to Page Down
"xte 'key Page_Up'"
b:9

"xte 'key Page_Down'"
b:8

Step 5: Test the Configuration.

xbindkey -v -s


Notes