问题
Having recently moved to Emacs (and become a fanboy), I'd like to use Autohotkey to make Ctrl+X Ctrk+C a universal "Close" command.
Here's what I have in my .ahk
file:
; Universal Close
:*:^x^c::
WinClose, A
Return
which doesn't appear to work. What am I doing wrong?
To clarify my keystrokes, here is the sequence:
- Hold down the CTRL key;
- Press and release the X key;
- Press and release the C key;
- Release the Ctrl key.
On either pressing or releasing the C key (I don't mind which), the active window is closed.
Success story: I have implemented the answer by Honest Abe, adding a small tweak to avoid annoyance when actually using Emacs itself. Here's the end result (thanks, H.A.!):
; Universal Close
$^x::
IfWinActive, ahk_class Emacs
Sendinput, ^x
Else {
keywait, c, d, t0.6
If ErrorLevel
Sendinput, ^x
Else
WinClose, A
}
Return
回答1:
Here is an example that waits 0.6 seconds for C to be pressed after Control + X:
$^x::
keywait, c, d, t0.6
If ErrorLevel
Sendinput, ^x
Else
WinClose, A
Return
If C is not pressed within 0.6 seconds Control + X is sent.$
is used at the very beginning when a hotkey sends itself (to avoid an infinite loop).
Manual references:
$
keywait
回答2:
While this isn't a direct answer to your question, you may want to look at XKeymacs if you haven't already, http://www.cam.hi-ho.ne.jp/oishi/indexen.html
It gives you ALOT of Emacs functionality within all/most windows apps. As with Emacs it is highly configurable, so you can enable/disable Emacs bindings on a global or application level.
It may not be the right solution for everyone, but I can't live without it.
来源:https://stackoverflow.com/questions/11973968/how-can-i-remap-ctrl-x-ctrl-c-in-autohotkey