Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr3819 :: Remapping Mouse Buttons with XBindKeys on Linux

I explain how I assigned different functions to the spare buttons on my trackball mice.

<< First, < Previous, , Latest >>

Thumbnail of Jon Kulp
Hosted by Jon Kulp on Thursday, 2023-03-23 is flagged as Clean and is released under a CC-BY-SA license.
Linux configuration, tips and tricks, mouse configuration, keymapping. 1.
The show is available on the Internet Archive at: https://archive.org/details/hpr3819

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:10:00

general.

Remapping Mouse Buttons with XBindKeys on Linux

After a really long time of not bothering to figure out how to do this, I finally did some research and found out how to remap the extra buttons on my Kensington Expert mouse and my Logitech marble trackball mouse in a Linux environment. The tools it needed were xvkbd, xdotool, and xbindkeys. I already had the first two installed, but had never used xbindkeys before. I also used xev to identify the button numbers and key numbers.

The Kensington Expert Mouse is one that I've had for about 15 years, and it was fairly expensive when I bought it, something like $75 or $80. It has four large buttons with a large trackball in the middle and a scroll wheel going around the track ball. I bought it at a time when I was doing a lot of graphic work that required clicking and dragging and double-clicking and stuff like that. If you're using it in a Mac or Windows environment, there is a special configuration tool that you can use to set it up just how you want. I had always configured it so that the upper left and upper right buttons were used for double-clicking and click dragging. This helped reduce a lot of strain on my hands. I have never gotten this to work on Linux, though, until today.

If you want to do this yourself, the first thing to do is make sure you have these packages installed: xvkbd, xdotool, and xbindkeys.

Then create a configuration file in your home directory:
~/.xbindkeysrc
In order to map the upper left button to "double click," and the upper right button to "click and drag," I added these lines to the configuration file:
# Double-click assigned to button 2 (upper left)

"xdotool sleep 0.2 click 1 ; xdotool click 1"
      b:2

# Click and Drag assigned to button 8 (upper right)

"xdotool sleep 0.2 mousedown 1"
      b:8
To test the settings, simply kill the xbindkeys process and restart it by typing xbindkeys:
user@hostname:~$ pkill -f xbindkeys
user@hostname:~$ xbindkeys

On my desktop computer I have a Logitech marble trackball mouse, and it has two small keys that are assigned to back and forward by default. This can be handy for navigating file managers and web pages, but I wanted them to be assigned to "page up" and "page down" (to make up for the lack of a scroll wheel on the mouse). Here is the configuration file for that machine:

"xvkbd  -text "\[Page_Down]""
       b:8

"xvkbd  -text "\[Page_Up]""
       b:9

I suppose I could have used xdotool for this configuration file as well, but for reasons I can't remember now, I tried xvkbd first and it worked, so I did not experiment further. I used xdotool for the Kensington because xvkbd did not have a way to perform virtual mouse clicks.

Links


Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2023-04-03 00:37:55 by Zen_floater2

LOOK EVERYBODY!!!

It's that Jon Kulp again!
I thought for sure they banished him from the internet for playing a musical instrument.
He's apparently out now!!!

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
Who is the host of this show?
What does HPR mean to you?