Linux System Info:
OS:        GNU/Linux x86_64
Kernel:    3.13.0-24-generic
Distro:    Linux Mint 17 Qiana, Cinnamon 64-bit 2.2.16
           [Based On: Ubuntu 14.04.5 LTS, Trusty Tahr]

Due to a disability (spinal injury) which includes finger impairment, I have made some alterations so that I can use my keyboard's CapsLock key as my left mouse button. NumLock is remapped to function as CapsLock.

Almost everything works fine when using CapsLock as a left-click and left-double-click but a few things, listed below, do not...

EDIT 2019-01-10

The rest of a long post has been deleted - see my answer below for how to set up the CapsLock key to act as a left mouse button with NumLock remapped to function as CapsLock.

  • 1
    XKB's mousekeys features might help, but I'm not sure if they can do what you need. I don't know exactly how that works, look at /usr/share/X11/xkb/compat/mousekeys. You'd bind <CAPS> to LockPointerButton(button=default). I don't know if you can bind the release action that way. – Gilles 'SO- stop being evil' Mar 3 '18 at 16:06
  • Thanks. I've explored using MouseKeys but don't think it can be used to allow CapsLock to function as a left mouse button replacement, with a press of CapsLock being left-button down and a release of CapsLock being left-button up. – mattst Mar 6 '18 at 15:46
  • What does xev tell you when you hit your modified CapsLock? Also I wonder if -option caps:none is correct; I would use capslock:none (there is no caps file in /usr/share/X11/xkb/symbols, only capslock). – L. Levrel Jan 9 '19 at 13:18
  • 1
    @L.Levrel I fixed the problem ages ago. To help others I've now answered my own question on how to set it up. – mattst Jan 10 '19 at 13:21

Answering my own question...

Setting up CapsLock as act as a left mouse button turned out to be much simpler than expected. [Note: The physical mouse left mouse button continues to behave as normal.]

1) Map CapsLock to the left mouse button (66 is the CapsLock key code):

$ xmodmap -e "keycode 66 = Pointer_Button1"

2) Map NumLock to CapsLock (77 is the NumLock key code):

$ xmodmap -e "keycode 77 = Caps_Lock"

Note: This means NumLock will act as the CapsLock replacement key, the functionality of NumLock will be lost (I never use it anyway but use a different key if you use NumLock, e.g. Pause, ScollLock, etc.).

3) Enable mousekeys:

$ xkbset mousekeys

Note: xkbset is not installed by default on some distros and this is not the same as enabling Mouse Keys in the Accessibility section of your system settings.

That's it - all done.

However users will probably want to have these tasks done automatically on start-up. Here's what I did:

Create the regular file /home/user/.Xmodmap and insert the following lines.

! 77 is the NumLock key code, 66 is the CapsLock key code.
! Map CapsLock to the left mouse button and map NumLock to
! CapsLock, i.e. NumLock acts as the CapsLock key used to.

keycode 77 = Caps_Lock
keycode 66 = Pointer_Button1

Note: Comments in .Xmodmap files start with an !.

Running xmodmap to load the ~/.Xmodmap file on start-up proved must harder than was expected - the problem being that it must be done very late in the start up sequence or XKB will not have been initiated and XKB will overwrite the xmodmap changes when it loads.

Placing the lines...

/usr/bin/xmodmap /home/user/.Xmodmap
/usr/bin/xkbset mousekeys

...in ~/.profile, ~/.xinitrc, and ~/.xsessionrc all failed.

Creating the file /etc/X11/Xsession.d/80_xmodmap_user_added to run the commands above, as suggested in How persistently remap keys in Ubuntu 16.04? did not work for me.

Reluctantly I used the graphical start up tool, on Linux Mint this is as follows (your distro may vary):

Mint Menu --> Preferences --> Startup Applications

I created 2 entries, one to call each of the following commands:

/usr/bin/xmodmap /home/user/.Xmodmap
/usr/bin/xkbset mousekeys

For the record I need no auto-start delay in my Startup Applications entries, but try adding a delay if this does not work for you. XKB needs to have been initiated before the commands are run or your changes will be over-ridden by it.

This all works perfectly for me; on start-up CapsLock functions as a left-button mouse key (both single and double clicking work).

  • @JigglyNaga Thanks for the pointer, you are right ! works for comment lines. I've updated my post accordingly. – mattst Jan 10 '19 at 18:05
  • I use shift+caps_lock for caps mode. keycode 66 = Pointer_Button1 Caps_Lock. no need to touch num_lock – Akhil Jalagam Apr 6 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.