He, Peng

A Roboticist.

The secret of getting ahead is getting started.

How To Bind Mouse Keys in Ubuntu & How To Swap Ctr and Alt on Ubuntu and Windows

Abstract: As an Ubuntu user, sometimes you want to use the function keys from a mouse, for example, the Logitech ones. However, there is no such a software offered by their website to do the same thing as in Windows. This blog will give a quick instruction on how to set it up.

Bind Mouse Key to a function key combo in Ubuntu

To use the feature on Ubuntu, you need install XEV, it may come with the system, if not, install it.

sudo apt-get install xbindkeys xautomation
xbindkeys --defaults > $HOME/.xbindkeysrc
gedit ~/.xbindkeysrc 

This will create your keybinding config file, after open it type xev in a terminal, it will pop up a small window and you should move your mouse into the window then click the key you want and finally confirm the key number on your terminal outputs.

My script for a Logitech M570 trackball mouse. Copy this to the ~/.xbindkeysrc if you like.

## Mouse lower button trace back to last page
"xte 'keydown Control_L' 'keydown Shift_L' 'key Tab' 'keyup Shift_L' 'keyup Control_L'"
## Mouse upper button close current tab
"xte 'keydown Control_R' 'key w' 'keyup Control_R'"


Swap Control key with Alt key on Ubuntu and Windows

The reason for this is to make my brain not being tire apart by frequently swapping between a Unix key system(MAC OS) and a Windows key system (Ubuntu & Windows) so I decide to swap the control and alt in a root level to make all shortcut keys function in a same way.

It is very easy in window, just use Sharpkey to create two mappings, even they say you are under a risk to use the software on Win10, but I find it works perfectly indeed.

Screenshot of the mapping

While in Ubuntu, it is a little bit hard.

install xmodmap if you don't have it, then do the following.

~$ gedit ~/.Xmodmap

That will create the file and open it in gedit. Add the following lines to the file:

clear control  
clear mod1  
keycode 37 = Alt_L Meta_L  
keycode 64 = Control_L  
add control = Control_L Control_R  
add mod1 = Alt_L Meta_L  

Save the file and quit gedit. Next time you login the new keymappings will be active. To have the settings take immediate effect run the following command:

~$ xmodmap ~/.Xmodmap

To auto start the config file:(Which I find is not working)

touch .xinitrc  
echo "xmodmap ~/.Xmodmap" >> .xinitrc  

Instead, if you are on Ubuntu 16.04, use the startup application (search from the launch) to add an new entry. Or you can go to here and create a new one.
The key point is this needs to be run from a terminal, so set the terminal as true. (I spent two hours on figuring out this)

Create a file like this:

subl .config/autostart/xmodmap.desktop  

Then put down the configs.

[Desktop Entry]
Exec=xmodmap /home/user/.Xmodmap  
Name[en_US]=Swap CTL with ALT  
Name=Swap CTL with ALT  
Comment[en_US]=call to start the xmod, needs the terminal bit to be true  
Comment=call to start the xmod  

You are all set.

Recent Posts

Robotics 101: Sharpening The Tools -- Shorthands For Environment Setups

Abstract: After month and month working in robotics, I realize that a good knowledge of tooling coul…

In ConfigsRead More
Earlier Posts

New Year New Posts

Life has gone hard when you have yourself only in a foreigner country. Robotics engineer is doing t…

In logRead More
comments powered by Disqus