Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bogdanRada/3c120e1b91d3ce0a4a5d6cbee82f69fb to your computer and use it in GitHub Desktop.
Save bogdanRada/3c120e1b91d3ce0a4a5d6cbee82f69fb to your computer and use it in GitHub Desktop.
Custom keymap for Logitech MX Master 2S mouse on Ubuntu

First, install Solaar to see the battery level on the taskbar

sudo apt-get install solaar

To remap the keys, install

sudo apt-get install xbindkeys xautomation

Then, launch xev to get the keyboard or mouse event to bind

xev

# grep button
xev | grep -i button

Create the configuration file for xbindkeys

nano ~/.xbindkeysrc

Here is an exemple of this file that map the Back and Forward buttons to BackSpace and Return respectively

# thumb wheel up => increase volume and unmute      
"amixer -D pulse set Master 4000+ unmute"
 b:6
                                        
# thumb wheel down => lower volume       
"amixer -D pulse set Master 4000-"       
 b:7
                                        
# backward button => previous song       
"xte 'key XF86AudioPrev'"                
 b:8
                                        
# forward button => next song            
"xte 'key XF86AudioNext'"                
 b:9
 
# Example backspace
#"xte 'keydown BackSpace'"
#b:8

#"xte 'keyup BackSpace'"
# b:8 + Release
 
# Alt tab to previous app
"xte 'keydown Alt_L' 'key Tab' 'keyup Alt_L'"
 b:9

To test your binding

xbindkeys -v

To start xbindkeys

xbindkeys

To find key code

xbindkeys --key

// or

xbindkeys --multikey

If you change the key map, you have to restart xbindkeys by following command

killall xbindkeys && xbindkeys
@bimalkharel
Copy link

Double thanks for pointing that out and attributing the work!

@ambitious-octopus
Copy link

ambitious-octopus commented Sep 27, 2021

Thanks, I spent an entire morning trying to get these two damn buttons to work! Here is the ultimate guide.
I also share my copy and paste setup in case anyone needs it. (With this combination, copy with the lower key and paste with the upper key. It also works in the terminal by holding down shift).

# thumb wheel up => increase volume and unmute      
"amixer -D pulse set Master 4000+ unmute"
 b:6

# thumb wheel down => lower volume       
"amixer -D pulse set Master 4000-"
 b:7

# copy       
"xte 'keydown Control_L' 'key c' 'keyup Control_L'"
 b:8

# paste            
"xte 'keydown Control_L' 'key v' 'keyup Control_L'"
 b:9

# terminal copy
"xte 'keydown Shift_L' 'keydown Control_L' 'key c' 'keyup Control_L' 'keyup Shift_L'"
 Shift+b:8

# terminal paste
"xte 'keydown Shift_L' 'keydown Control_L' 'key v' 'keyup Control_L' 'keyup Shift_L'"
 Shift+b:9

@ockty
Copy link

ockty commented Feb 10, 2023

Thanks, that was good except for 2 buttons that I can not seem to map:

  • the little button that is just underneath the scroll (that usually has the purpose to change the scroll type)
  • the button that you press down with your thumb.

Has anybody managed to remap those keys ? Thanks

@JaxonWright
Copy link

For anyone who has an MX Master 3, the thumb wheel numbers need to be reversed. So, b:7 is up and b:6 is down

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment