Ubuntu – binding back/forward to mouse buttons

bindbuttoninput-devicesmouse

I have a basic logitech mouse with 5 buttons: left, right, wheel left, wheel, wheel right.

I used to use wheel left and right for going back and forward in my browser or navigator. Now this doesn't work. I've found many solutions, people telling to install this program or that, didn't seem to work.

Best Answer

  1. Install the package xautomation, we need the command xte

    sudo apt-get install xautomation
    
  2. Install the package x11-utils, we need the command xev

    sudo apt-get install x11-utils
    
  3. Check the code for the two mouse buttons.

    • Start the command xev in a terminal:

      xev
      
    • Move the mouse in the new window

    • Press your wheel left and wheel right

    In my case, note the output button 6 and button 7:

    ButtonRelease event, serial 36, synthetic NO, window 0x2e00001,
        root 0x233, subw 0x0, time 9222464, (94,21), root:(1774,85),
        state 0x10, button 6, same_screen YES
    
    ButtonPress event, serial 36, synthetic NO, window 0x2e00001,
        root 0x233, subw 0x0, time 9223854, (94,21), root:(1774,85),
        state 0x10, button 7, same_screen YES
    
  4. Edit your xbindkeys configuration, e.g.:

    nano ~/.xbindkeysrc
    

    and add the lines below

    "xte 'keydown Alt_L' 'keydown Left' 'keyup Left' 'keyup Alt_L'"
         b:6
    
    "xte 'keydown Alt_L' 'keydown Right' 'keyup Right' 'keyup Alt_L'"
         b:7
    

    Replace b:6 and b:7 with your numbers of xev output

    • from man xte

      key k
            Press and release key k
      
      keydown  k
            Press key k down
      
      keyup k
            Release key k
      
  5. Kill all kbindkeys processes

    killall xbindkeys
    
  6. Restart xbindkeys with your configuration, eg:

    xbindkeys -f ~/.xbindkeysrc