This is a quick tutorial for using BTNX, which is a Linux application that you can use to assign commands to the extra buttons on your mouse.  This is primarily for Logitech mice (which is all I’ve tested it with) but I think it should work with other mice.  I found this application after going for a few months wishing that I could find a way to assign custom commands to the extra buttons on my Logitech MX310.  Eventually, I finally found time on a Sunday to find a solution and I found BTNX.  I tried to look for tutorials, and I did find this thread on the Ubuntu Forums, but the instructions were cluttered and confusing at times.  That is the reason for this post, in the hopes that people will find these instructions concise and easy to follow.

Setup

So here we go, if you have a mouse with extra buttons and you want to USE those extra buttons, the first step is to install BTNX by opening up a terminal and running,

sudo apt-get install btnx

This should also install btnx-config, which is the GUI to edit your settings.

Once you’ve got that installed, open up BTNX from the menu or run

gksudo btnx-config

in the terminal.  You’ll get a password prompt and then you should be greeted with the following screen:

Unless it’s already detected all of your mouse’s buttons, it will have a “0” next to “Detected buttons”.  If you see a zero there, the next step is to click that huge button on the right that says “Detect mouse & buttons”.  And you should see this:

Hit “Press to start button detection”.  At the prompt, click ONE BUTTON until the bar is full, DO NOT press other buttons while it’s being detected, otherwise you’ll have to start the detection over.  Once the progress bar is full, you should see this:

Name your button something that’s easy to remember, like Left Click, or Scroll Up.  Click the Add button, and then proceed to detect and name the rest of your buttons.  Don’t forget that scrolling up and down and clicking the scroll wheel are all their own buttons!  Once you’ve detected all of your buttons, click the ok button in the screen above.  You should see this screen again.

If you did it right, the number beside Detected buttons should correspond to the number of buttons you have on your mouse.  Right at the top, you should see four tabs.  Click on the one that says Buttons.

Hurray! If you did everything right, you should now see a list of all your buttons on the left.  Now comes the fun part.

Above is the default screen for a new button.  Now, you get to assign whatever you like to your buttons!  At the very top is a checkbox marked Enabled.  Do NOT check that box for your default buttons (left click, right click, scroll up and down etc. [Well, you can if you want to, but I haven’t tested that out yet, and I have a feeling that might mess some things up])

Here’s a brief run down of the Event Type variables, I’ll give a more in-depth guide of each option directly after:

  • Key combination – simulates a keystroke such as Super + A or CTRL + ALT + DELETE.
  • Configuration Switch – lets you switch button configurations.  You can add configurations at the first tab at the top of the screen.  More on this later.
  • Command execution – run a command with that button.  For example, you can assign gnome-terminal to open whenever you press that button.

Key Combination

I currently have Tile and Expo hotkeys assigned to a few of my buttons.  I’m running Compiz, so it’s a simple process to set up a keyboard shortcut to run Tile for example, and then set a button to simulate those keystrokes.

My Compiz Expo shortcut is set to Super + E.  It’s easy to select the keycode and up to three modifiers that you need to simulate a keystroke shortcut, just select the keys from the dropdown list.  For me, all I had to do was select KEY_E as the keycode and then select KEY_LEFTMETA for teh modifier.  That button would now simulate an E + META.  The list of keycodes is extensive, and remember, you don’t need to use a modifier if you just want to simulate F11 for example.  In BTNX and some other applications, Super, or the Windows Key, is referred to as META, this caused some confusion for me when I was first exploring Linux.

Configuration Switch

With this, you can assign a button to swap between different button profiles.

This is useful if you want to have different configurations for different applications, such as a media configuration, in which all the buttons control media playing, or a window management configuration, with all window manager shortcuts.  Basically, the configuration switch lets you swap between your different button configurations.  I’ll talk more about this below.

Command Execution

Choosing this will basically wire a command directly to that button.  I.e. assigning gnome-terminal to scroll click will open a terminal every time one scroll clicks.  I haven’t been able to get this working myself, but I’ll keep working and hopefully I’ll post an update sometime soon.

Configurations

Configurations are basically like profiles.  Each configuration is a list of settings for your mouse.  If you want to have different configurations for different applications, that’s perfectly fine.  One example is a media configuration, with buttons controlling play/pause, volume, etc.  Other examples could be a work oriented configuration, with buttons controlling window management, tab switching, workspace switching etc.  The possibilities are endless.  If you want an easy way to swap through your configurations, just map a button to the Configuration Switcher (see above).

Revoco

These are advanced settings for people with an MX Revolution mouse.  I don’t have enough cash to burn to get myself one at the moment, so this will go untested for the time being =).

Advanced

These are basically initiation options for BTNX, giving you options on when to start-up BTNX.

Troubleshooting

As with everything, there’s always the possibility that you can run into problems.  I personally had problems with getting the buttons to do anything.  I fixed this by going into the config file and editing it manually.  One of the biggest problems was that sometimes I would click the button after changing the key combination but nothing would happen.  If this happens to you, here’s how to fix it:

Make sure that btnx-config is closed.  Open a terminal and enter

sudo gedit

Click open and navigate to /etc/btnx/ and open the file named btnx_config_[configuration name]

Search for the name of the problematic button that you entered and find the Button entry

Here was the original entry for mine:

Button
 name = Right Side
 rawcode = 0x01000114
 enabled = 1
 type = 0
 delay = 0
 force_release = 0
 keycode = KEY_A
 mod1 = KEY_LEFTMETA
 mod2 = NONE
 mod3 = NONE
 EndButton

To get it working, change the value of “type” from 0 to 1 like so:

Button
 name = Right Side
 rawcode = 0x01000114
 enabled = 1
 type = 1
 delay = 0
 force_release = 0
 keycode = KEY_A
 mod1 = KEY_LEFTMETA
 mod2 = NONE
 mod3 = NONE
 EndButton

Save it, open a terminal, and run

sudo btnx

That should get the button working.

EndEntry

Hopefully, this was helpful. I won’t presume to think that anyone will ever read this, but it’s a cool possibility.  Here’s the custom configuration for my Logitech MX310 below:

 # This is a btnx configuration file generated by btnx-config
Mouse
 vendor_id = 0x046d
 product_id = 0xc01b
 revoco_mode = 0
 revoco_btn = 3
 revoco_up_scroll = 5
 revoco_down_scroll = 5
 EndMouse
Button
 name = Left Click
 rawcode = 0x01000110
 enabled = 0
 type = 0
 delay = 0
 force_release = 0
 keycode = NONE
 mod1 = NONE
 mod2 = NONE
 mod3 = NONE
 EndButton
Button
 name = Right Click
 rawcode = 0x01000111
 enabled = 0
 type = 0
 delay = 0
 force_release = 0
 keycode = NONE
 mod1 = NONE
 mod2 = NONE
 mod3 = NONE
 EndButton
Button
 name = Scroll Click
 rawcode = 0x01000112
 enabled = 0
 type = 0
 delay = 0
 force_release = 0
 keycode = BTN_MIDDLE
 mod1 = NONE
 mod2 = NONE
 mod3 = NONE
 EndButton
Button
 name = Left Side
 rawcode = 0x01000113
 enabled = 1
 type = 0
 delay = 0
 force_release = 0
 keycode = KEY_PLAYPAUSE
 mod1 = NONE
 mod2 = NONE
 mod3 = NONE
 EndButton
Button
 name = Right Side
 rawcode = 0x01000114
 enabled = 1
 type = 1
 delay = 0
 force_release = 0
 keycode = KEY_A
 mod1 = KEY_LEFTMETA
 mod2 = NONE
 mod3 = NONE
 EndButton
Button
 name = Scroll Up
 rawcode = 0x02010008
 enabled = 0
 type = 1
 delay = 0
 force_release = 0
 keycode = KEY_SCROLLUP
 mod1 = NONE
 mod2 = NONE
 mod3 = NONE
 EndButton
Button
 name = Scroll Down
 rawcode = 0x02ff0008
 enabled = 0
 type = 1
 delay = 0
 force_release = 0
 keycode = KEY_SCROLLDOWN
 mod1 = NONE
 mod2 = NONE
 mod3 = NONE
 EndButton
Button
 name = Tile
 rawcode = 0x01000115
 enabled = 1
 type = 1
 delay = 0
 force_release = 1
 keycode = KEY_E
 mod1 = KEY_LEFTMETA
 mod2 = NONE
 mod3 = NONE
 EndButton

– Paco

Sources:

btnx: Send keyboard and mouse combination events with mouse buttons @ Ubuntu Forums

Good shortcuts for your mouse @ Ubuntu Forums

Advertisements

About Paco

#RomanCatholic | #ProLife | #Homeschooler | #EagleScout | #Arrowman | Life philosophy: Adventure!; +AMDG+; Ad Jesum Per Mariam

Have something to say?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s