How can I remap CTRL-x CTRL-c in Autohotkey?

2019-05-05 23:04发布

问题:

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:

  1. Hold down the CTRL key;
  2. Press and release the X key;
  3. Press and release the C key;
  4. 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.



标签: autohotkey