Mapping Caps Lock to Control from within Emacs on Windows

天大地大妈咪最大 提交于 2019-11-30 14:57:07

问题


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.


回答1:


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.




回答2:


I believe it doesn't work because Windows (or X) doesn't pass an actual event for [capslock] or [control] - it's a modifier key, like [shift]. Pressing a modifier key doesn't cause the application to get a keystroke, but if you press a modifier and a second (non-modifier) key, then you get the keystroke.

For example [a] and [A] are two different keys, one is the regular "a" and the other is essentially "shift-a". I'm sure you could set Windows up to have the "shift-a" actually send a "z" or something.

Because [capslock], [control], [shift], [meta] are all modifier keys, they don't generate key events in and of themselves for the applications.

In short, Emacs doesn't get a [control] key event that it can remap, it gets a C-a event. This is generally done by the obvious combination of [control] and [a] keys. But, the event could be generated by a different keystroke, say [F10] or even [y] (confusing, yes).

This is how I understand it. Clarifications are welcome of course.




回答3:


The simplest way to remap CapsLock on Windows is to download this CapsLockChanger utility, choose a key to map to (Control) and put it in your Start->Startup menu.

It stays in your tray, does the job on key remapping and does not require messing around with registry.




回答4:


You do not necessarily need Admin rights in order to modify the registry.
In fact, the Windows Registry is a segmented resource, much like a filesystem, and you can have granular permissions on various branches and nodes within the registry. Are you sure your assumption that you cannot change the registry, is correct? I think it is true by default on Vista, but not on previous Windows.



来源:https://stackoverflow.com/questions/840478/mapping-caps-lock-to-control-from-within-emacs-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!