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

我只是一个虾纸丫 提交于 2019-12-07 08:10:28

问题


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.



来源:https://stackoverflow.com/questions/11973968/how-can-i-remap-ctrl-x-ctrl-c-in-autohotkey

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