Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping Caps Lock to Control from within Emacs on Windows

When reading either of these questions or the EmacsWiki article about mapping Caps Lock to Control in emacs in Windows, the best answers seem to involve the registry. My question is what a user can do when they can't modify the registry of the machine because they don't have admin rights. Is there a way to do the mapping from within emacs? This article comes oh-so-close, even saying, "As people have mentioned, you can of course map Caps-Lock to other keys instead, for example the Control key." But I can't figure out how to represent the control key (using various references that look pretty comprehensive but might not be Windows-centric), trying things like

(setq w32-enable-caps-lock nil)
(global-set-key [capslock] '[control])

and

(setq w32-enable-caps-lock nil)
(global-set-key [capslock] 'ctl-x-map)

which don't seem to work.

like image 523
Brendan Foote Avatar asked May 08 '09 15:05

Brendan Foote


1 Answers

I know this does not really answer your question, but Trey Jackson basically explained the problem. To detect control key alone requires low-level keyboard hook on Windows, which I don't think Emacs implements.

One way (involving external program, but does not require admin right) is to use AutoHotkey. All you need is the following 2 line script:

CapsLock::Ctrl
LCtrl::Capslock

You will need to run this script whenever emacs is open, but thankfully Autohotkey is pretty low profile application (usually takes about a few hundreds Kb in memory only). You can for example execute this script in your .emacs so that your control key and capslock key are swapped whenever emacs is opened.

like image 119
polyglot Avatar answered Sep 16 '22 16:09

polyglot