What do you think? Discuss, post comments, or ask questions at the end of this article [More about me]

On one of my laptops (Razer Blade 15) running Manjaro i3 community edition I found the touchpad to be a little stiff when pressing the pad as a button.  For some reason I just don't get along with touchpads that you "tap" for button presses so I usually disable this (see here for how to disable tapping in libinput) and click the whole touchpad instead.  Anyway, for the touchpad on the Razer Blade 15 it's hard to press and actually starts to feel quite uncomfortable after a while with continual clicking.

I initially thought I should just toughen up my clicking finger (smile) but then noticed that I never use the right alt and ctrl keys on my keyboard, and they're kind of placed near the touchpad... so why not just map touchpad clicks to these keys? 

This is quite straight forward using xmodmap and xkbset.

Guide

Install packages

We're going to install several packages and a utility which will identify the keycodes for our keys (which we will map to mouse buttons).

Note, in this example we'll be installing on an Arch based distro so will be using pacman and yay (an AUR helper) but these packages should be in your distro's package manager.

Let's first install xmodmap, xev (utility to identify input keycodes) and xkbset:

sudo pacman -S xorg-xmodmap xorg-xev
yay -S xkbset

Configuration

We'll xkbset to enable mousekeys (i.e. enable us to use keyboard keys as mouse buttons).  We're going to enable mouse keys with by adding several lines to our .profile.  This is required to have the mousekeys setting survive a reboot and load every time you login.

Add the following lines to your .profile:

# enable mousekeys (my xmodmap has mousekeys mapped to buttons)
/usr/bin/xkbset exp =m
/usr/bin/xkbset m

Next, we're going to make a copy of our current keyboard layout and add this as a file which will be loaded when we start an X session (like when you login etc.).  Do the following from a terminal

xmodmap -pke > ~/.Xmodmap

This will create a copy of the current keyboard layout which we will now modify to map several mouse buttons to specific keys.  Load the file you just created into your editor of choice (mine being vim...):

vim ~/.Xmodmap

Once open in the editor you should notice several columns, the first contain "keycode" followed the by key (code) for all keys on the keyboard, followed by what this key maps to.

We need to now find the keycode for the keys we want to remap.  We can use "xev" for this.  Open a terminal and type

xev

This should open another window which will capture any key (or mouse button) event and output (among other things) the key code.  From the output of xev I found that the keycodes I wanted to remap were:

  • keycode 108 (which is my right cntrl button)
  • keycode 105 (which is my right alt button)

All we need to do now is modify the .Xmodmap conf file we created in the previous step with the following:

keycode 105 = Pointer_Button3 NoSymbol Pointer_Button3
keycode 108 = Pointer_Button1 NoSymbol Pointer_Button1

Note, you'll likely need to logout/login for the mappings to activate.

And there you have it... no more sore fingers from constantly clicking that trackpad.

References

  1. https://wiki.archlinux.org/index.php/xmodmap