My previous laptop (Asus) had a special key on its keyboard to toggle the touchpad. It was working out of the box with Linux Mint & the Mate desktop environment – there was a special support for it. My new laptop (HP) doesn’t have this special key and I was really missing it. This article is about how to add a key binding under Linux that will be behaving exactly as having such a special key (tested on Ubuntu 16.04 LTS and Cinnamon 3.4.6).
Let’s identify what is a keycode that is recognized by a desktop environment as a signal to toggle the touchpad. To discover this run the command:
xmodmap -pke|grep -i touchpad
On my computer results look as follows:
$ xmodmap -pke|grep -i touchpad keycode 199 = XF86TouchpadToggle NoSymbol XF86TouchpadToggle keycode 200 = XF86TouchpadOn NoSymbol XF86TouchpadOn keycode 201 = XF86TouchpadOff NoSymbol XF86TouchpadOff
So now we know keycode 199 is the one recognized as toggling the touchpad.
Now we need a program that can simulate pressing a key with such a keycode. I found this can be done by xdotool. I needed to install it with the following command:
sudo apt install xdotool
Now you can test the program with the command:
xdotool key 199
For me it worked like a charm.
Finally we need to setup a key binding that will run the above command actually toggling the touchpad. In the Cinnamon desktop environment one does this as follows (optionally you can refer the section 15. Custom Keyboard Shortcuts of How To Change The Linux Mint Cinnamon Keyboard Shortcuts):
- Open system settings window
- Click on “Keyboard” item
- Go to “Shortcuts”
- Click on “Add custom shortcut” button
- Enter a name for a key binding (something like “touchpad toggling”)
- Enter a command:
xdotool key 199
- Click on “Add” button
- Now select the first “unassigned” item in “Keyboard bindings” section and click it again to activate key capturing
- Press a key or a key combination of your choice
I used just F5 key for this and it’s working great. I have to admit that initially I wanted a key combination of windows-key+F5 but it was not working, but this is some issue with windows-key (it’s named SUPER key under Linux) and Cinnamon.
In my opinion this case is another example of how elastic Linux and open source software are. And it’s great!