How can I map keyboard buttons to my mouse buttons?

8,598
  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 extra mouse buttons

    In my case, note the output button 8 and button 9:

    ButtonRelease event, serial 36, synthetic NO, window 0x2e00001,
        root 0x233, subw 0x0, time 9222464, (94,21), root:(1774,85),
        state 0x10, button 8, 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 9, same_screen YES
    
  4. Edit your xbindkeys configuration, e.g.:

    nano ~/.xbindkeysrc
    

    and add the following lines

    "xte 'key Home'"
         b:9
    
    "xte 'key End'"
         b:8
    

    Replace b:8 and b:9 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
    
Share:
8,598

Related videos on Youtube

TuxForLife
Author by

TuxForLife

TuxForLife

Updated on September 18, 2022

Comments

  • TuxForLife
    TuxForLife over 1 year

    I have 2 extra buttons on my mouse that I would like to map as "Home" and "End"

    I am able to map mouse buttons to my keyboard using xkbset, but I would like to do the reverse and map keyboard buttons to my mouse.

    Output of xbindkeys here.

    • Admin
      Admin almost 9 years
      xbindkeys is what you need. Please do a sudo apt-get install xbindkeys* and edit your question and post the output of xbindkeys --defaults
    • Admin
      Admin almost 9 years
      There it is Fabby
  • TuxForLife
    TuxForLife almost 9 years
    Hey A.B. I got it to work, thank you. One final question. I was also considering switching the extra buttons to "Up" or "Down" arrows. I tried it and it worked, but I would like the ability to hold the extra mouse buttons, and have the multiple Up/Down signals, until I release the button. (just how the native Up/Down buttons work)
  • A.B.
    A.B. almost 9 years
    Cursor Up and Down? Or Page Up and Down?
  • TuxForLife
    TuxForLife almost 9 years
    The Up/Down arrow buttons. If you were to hold Up right now, it would send it as multiple up arrow strokes until you release the button. I would like to do the same for the extra mouse buttons we are modifying.
  • TuxForLife
    TuxForLife almost 9 years
    P.S. BitTrip Runner is awesome :)
  • TuxForLife
    TuxForLife almost 9 years
    Also, I can't give you the bounty points until 21 hours, just so you know
  • A.B.
    A.B. almost 9 years
    Repetitions are difficult. I'm still looking.
  • A.B.
    A.B. almost 9 years
    Sorry, no success. Maybe you should ask a new question. :\
  • Hippolippo
    Hippolippo almost 4 years
    Is it possible to use this to press multiple keys at once