22

I have a Logitech MX400 Laser Mouse which has 5 buttons + 4 for vertical/horizontal scrolling. I would like it set up so instead of horizontal scrolling pressing right on the scrollwheel will send Ctrl+Tab and left will send Ctrl+Shift+Tab, which will allow me to cycle through tabs in browsers.

Also, it would be nice if I could remap the middle button to one of the ones on the side as it is really hard to press down.

Another bonus would be if I could write a script that allows me to define what buttons do what dependent on which window is currently active.

I have tried using xmodmap but I could only see how to rearrange buttons, not have them send key signals.

Thanks in advance.


Button Map (using xev):

Left        1
Middle      2
Right       3
ScrollUp    4
ScrollDown  5
ScrollLeft  6
ScrollRight 7
Backward    8
Forward     9

3 Answers 3

22

The xbindkeys and xte can help you.

For example my .xbindkeysrc file looks like this:

# close the window under the mouse cursor
"xte 'mouseclick 1' && xte 'keydown Alt_L' 'key F4' 'keyup Alt_L'"
  b:8+Release

# double click
"xte 'mouseclick 1' 'mouseclick 1'"
  b:9
3
  • This is fantastic and extensible, many many thanks Oct 23, 2010 at 14:11
  • 1
    To get xte on Ubuntu 16.x, you'll have to install xautomation from apt. Dec 26, 2016 at 15:09
  • That doesn't work as well as I like, because it doesn't work the same if I hold the button down. My old mouse had a button that enables the scroll wheel to spin freely, which is great if I just want to start it moving real fast and scroll a long way. But my new one doesn't have that, so I bound two buttons on the side (I think they're designed as back/forward buttons for Web browsing) to the PgUp/PgDn keys. But I have to press them repeatedly if I want to keep scrolling; I can't just hold them down. How do I make it hold the key as long as I hold the button?
    – Sparkette
    Dec 28, 2016 at 1:52
9

Thanks to everyone for the solution. Here is a more foolproof/combined guide (done on Xubuntu 18.04).

  1. Open a terminal (like xterm/terminal/terminator), become root (sudo su -) or use sudo in front of the command:

    apt install xbindkeys xautomation
    
  2. Check the button mapping with xev, for this you don't need root permission so exit the root session (with exit) or open another terminal as user.

    xev | grep button
    
  3. A small window will appear. You have to move the mouse into that window and press the button you want to remap. An example output in the terminal will be:

    state 0x0, button 8, same_screen YES
    

    This is the 2nd side button on my mouse which I want to use as PAGE_DOWN.

    state 0x0, button 9, same_screen YES
    

    This is the 1st (yes, the order is reversed) side button I want to use as PAGE_UP.

  4. When you have all buttons you want to remap you can close the small xev window. Open your favorite editor (gedit/vi/nano for example) and edit the configuration file.

    vi .xbindkeysrc
    
  5. If you already have some content in the file, look if there is already a binding like it (unlikely, not by default) and add at the end.

    #Pagedown press
    "xte 'keydown Next'"
    b:8
    
    #Pagedown release
    "xte 'keyup Next'"
    b:8 + Release
    
    #Pagedup press
    "xte 'keydown Prior'"
    b:9
    
    #Pageup release
    "xte 'keyup Prior'"
    b:9 + Release
    

    Note: you need two entries, one for the button press and one for the release.

  6. The buttons 8+9 will be mapped to the keys "Next" (which is PAGE_DOWN) and "Prior" (PAGE_UP). If you want to map different keys you can find the keysymbol with xev.

    xev | grep keysym
    
  7. Like before, start it in a terminal, move the mouse to the small window and press the wanted key.

    state 0x0, keycode 117 (keysym 0xff56, Next), same_screen YES,
    
  8. Save and kill xbindings.

    killall xbindkeys ; xbindkeys
    

You can now use the additional side buttons on the mouse. The setting will be loaded automatically on next reboot/login. You only need the killall [...] command from above if you change the settings.

0

For me, and my Logitech G402 mouse, the Piper mouse configuration tool worked perfectly!

https://github.com/libratbag/piper

installable via apt

sudo apt install piper

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .