How to get a keycode from my mouse's side button?

All we need is an easy explanation of the problem, so here it is.

In my .bashrc, I would like to add this line :

xmodmap -e "keycode 135 = Return"

where the keycode number is the one from my mouse’s side button.

To find a keycode from the keyboard, I use xev, which gives me, for instance:

(the line that contains "keycode 135" is the one that matters)

 KeyPress event, serial 38, synthetic NO, window 0x6400001,    
     root 0x7c3, subw 0x0, time 30530179, (-489,479), root:(1047,479),    
     state 0x0, keycode 135 (keysym 0xff0d, Return), same_screen YES,    
     XKeysymToKeycode returns keycode: 36 "   XLookupString gives 1 bytes: (0d) " "   XmbLookupString gives 1 bytes: (0d) "    
     XFilterEvent returns: False

However, for a mouse, it doesn’t show the keycode:

ButtonRelease event, serial 38, synthetic NO, window 0x6400001,
    root 0x7c3, subw 0x0, time 30661669, (35,100), root:(1571,100),
    state 0x0, button 8, same_screen YES

How to get a keycode from my mouse’s side button, to use the command xmodmap, to simulate a keyboard’s key press from a mouse button? (for instance, pressing the side button would be as if I would press "a" on keyboard – and would show "a" in a text editor)

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You can’t, at least not with only xmodmap — mice and keyboards are handled differently, and mice don’t produce keycodes.

There are however tools which can remap input events across different device types; try Key Mapper for example. (I’m a very minor contributor to the project.)

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply