I want CapsLock key on my keyboard to act like the left mouse button. I want to be able to perform clicks, double clicks, send mouse down and mouse up events etc.

Now I am using AutoHotkey and the following script


The script works but not in every app and not every time. For example, it doesn't work in Task Manager, it usually doesn't work in installer UIs and some other places.

The script / AutoHotkey also doesn't work in windows of apps under some load. For example, if the app is performing heavy IO then the script might or might not work.

This is annoying to have intermittent issues with the approach.

So, please provide some advice on how to improve the script or maybe recommend some better alternatives than AutoHotkey.


4 Answers 4


The question does not specify the Windowing/Operating system (although one might be tempted to guess...), so for completeness this is the answer in (modern) X11:

  1. find keycode corresponding to CapsLock - e.g. by running xev and looking for keycode in the output while pressing CapsLock:

    $ xev | grep keycode state 0x10, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES, state 0x12, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES, If you are using "normal" (i.e. PC) keyboard it should be 66

  2. enable mousekeys:

    $ xkbset m

  3. map the keys you want:

    xmodmap -e 'keycode 66 = Pointer_Button1'

or, if you want to be fancy, keep Caps_Lock with some modifier:

xmodmap  -e 'keycode 66 = Pointer_Button1 Caps_Lock'

will keep the CapsLock functionality if you press Shift+CapsLock

  • I appreciate this because I use AHK in that other OS and now wanted the same thing in this OS that uses X11. Only problem is, I actually user my numpad for entering numbers, and this breaks that. Feb 27, 2019 at 2:47

For an easy solution, I suggest to set up mouse keys: Control Panel\All Control Panel Items\Ease of Access Center\Set up Mouse Keys

This will enable to use your keyboard as a mouse by using the numpad area.
How to use guide.

If You want to customize it, by altering the keys, than I suggest using NeatMouse.

NeatMouse has English, French, German, Greek, Italian, Polish and Ukrainian translations. Both regular and portable versions are available. It is small, convenient, efficient and completely free!

  • I've had a look at these and Mouse Keys are definitely not something I want because they are not configurable and look like inconvenient for a left hand. NeatMouse probably won't help either. It can't use CapsLock as a left mouse key.
    – Bobrovsky
    Jul 30, 2015 at 21:34
  • @Bobrovsky - The description said that it can use them as well. Are You sure CapsLock can not be configured?
    – Divin3
    Jul 30, 2015 at 21:40
  • I did try and was unable to do that with NeatMouse.
    – Bobrovsky
    Jul 31, 2015 at 15:59
  • @Bobrovsky - there is also a way from the registry to change it: howtogeek.com/howto/windows-vista/… You just need to find the binary code of the left click
    – Divin3
    Jul 31, 2015 at 20:07

Ok, it turns out there is a hack that enables AutoHotkey to work in Task Manager etc.

Enable interaction with administrative programs

Tried that. It worked. So far so good.


In the spirit of Radovan Garabik's answer (for those of us using an X11 based OS, e.g. Kubuntu .. if you are using Windows this is not for you, stick with the AutoHotKey solutions.) I got this to work without disabling my numpad. This requires the xbindkeys and xdotool packages installed on your system.

I was looking for CapsLock = left click, which should be similar. After much experimentation I realized I got better results with xdotool instead of xte.

In my ~/.bashrc (or whatever startup script is appropriate to your system) I added this line:

/usr/bin/xmodmap -e "keycode 66 ="

This removes the 'locking' behavior of Caps Lock and assigns that key (key 66) to nothingness. I was tinkering with putting this in other places like .xinitrc, but they never worked. It is fairly safe in .bashrc even though it does get re-run with every terminal session opened (depending on how your .bashrc is set up overall).

For xbindkeys I created the file ~/.xbindkeysrc with these lines:

"xdotool mousedown 1"

"xdotool mouseup 1"
  release + c:66

A reboot or running source ~/.bashrc should make the xmodmap part work. To reload xbindkeys, try this:

killall xbindkeys
xbindkeys -f ~/.xbindkeysrc

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.