Changing mouse button mapping in X (xinput)

From Akionux-wiki
Share/Save/Bookmark
Jump to: navigation, search

Abstract

xinput is an utility to configure and test X input devices.

I will change mouse button mapping by using xinput.

Steps

Input devices are listed by xinput --list:

% xinput --list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ USB       USB LASER MOUSE               	id=8	[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)]
    ↳ Power Button                            	id=7	[slave  keyboard (3)]
    ↳      SCISSORS Keyboard + 2P Hub         	id=9	[slave  keyboard (3)]
    ↳ Eee PC WMI hotkeys                      	id=10	[slave  keyboard (3)]

In this case, my mouse is recognized as "USB USB LASER MOUSE" and its id=8.

To display the button mapping, execute following command:

xinput get-button-map <device_id>

For example of id=8 in above case,

% xinput get-button-map 8
1 2 3 4 5 6 7 8 9 10 11 12 13

This integer sequence means the number of logical button mapped on i-th physical button. This sequence is

<1st physical button> <2nd physical button> ...

So,

1 2 3 ...

means i-th logical button is mapped to i-th physical button.

"0" means disable the physical button. If you want to disable a button, map it to "0".

To change the mapping, you will need to know which physical button has which number.

To know the number, keep clicking the button(s) you want to change mapping and execute query-state command:

xinput query-state <device_id>

For example,

% xinput query-state 8
2 classes :
ButtonClass
	button[1]=up
	button[2]=up
	button[3]=up
	button[4]=up
	button[5]=up
	button[6]=up
	button[7]=up
	button[8]=down
	button[9]=up
	button[10]=up
	button[11]=up
	button[12]=up
	button[13]=up
ValuatorClass Mode=Relative Proximity=In
	valuator[0]=1245
	valuator[1]=649
	valuator[2]=-1151

In this case, 8th button is down and you will know which button is the 8th button.

To change the mapping, run

xinput set-button-map <device_id> map_button_1 [map_button_2 [...]]

For example, to disable 8th and 9th physical buttons, run

xinput set-button-map 8 1 2 3 4 5 6 7 0 0 10 11 12 13

You can also map one logical button to more than one logical buttons:

xinput set-button-map 8 1 2 3 4 5 6 7 1 3 10 11 12 13

or swap buttons:

xinput set-button-map 8 3 2 1 4 5 6 7 8 9 10 11 12 13

References