【问题标题】:Autohotkey: How to implement an exit sequenceAutohotkey:如何实现退出序列
【发布时间】:2014-10-27 15:36:35
【问题描述】:

为了结束我的自定义键盘映射以进行编码,我在脚本底部放置了以下行:

Esc::ExitApp

但是,由于其他原因,单次击键(尤其是 Esc)发生次数过多。因此,我更喜欢单次击键序列(不按住任何键)来退出 Autohotkey 映射,例如“Esc 然后 LCtrl”或“Esc、LCtrl 然后再 Esc”

我已经尝试过AutoHotKey key SEQUENCE, not just single-key hotkey 的想法:

Esc::
Input Key, L1
if Key=LCtrl 
ExitApp  
return

但它似乎没有奏效:按 Esc 然后按 LCtrl,映射不会停止。 (另外,如果我按下 Esc,然后按下另一个键(不是 LCtrl),下一次击键将被忽略,我最好不要。

【问题讨论】:

  • 为什么链接问题中的建议没有起到作用?请发布您的代码并说明什么不起作用。
  • 我已经添加了我尝试过的具体代码。
  • 看看Input docs。为了捕捉非字符键,您可以定义EndKeys。无论如何,你为什么不直接使用像^ESC^+ESC 这样的本机热键?当意外触发您的例程时,它同样安全,并且会为您节省大量脚本编写麻烦。

标签: sequence autohotkey exit


【解决方案1】:

版本 1a:

LCtrl & Esc::
ExitApp
return

您可以在脚本中的任何位置添加此代码。按 LCtrl 并在 Esc 之后退出脚本。

版本 1b:

Esc & LCtrl::
ExitApp
return

您可以在脚本中的任何位置添加此代码。按 Esc 并在 LCtrl 之后退出脚本。

您可以同时添加版本 1a版本 1b。在这种情况下,当您按 LCtrl 并在 Esc OR EscLCtrl之后> 脚本将退出。


版本 2(它使用不同的方法,如果由于某种原因您不喜欢 版本 1a 或/和 版本 1b ):

Loop
{
    a := GetKeyState("Esc")
    if (a=1)
    {
        b := GetKeyState("LCtrl")

        if (b=1)
        {
            ExitApp
        }

    }
}

该代码应该在您的其他代码重新映射您需要的所有键之后启动。按 LCtrlEsc OR EscLCtrl 之后脚本退出。


编辑:

第 3 版

Loop
{
    a := GetKeyState("Esc")
    if (a=1)
    {
        Loop,60 ;number of 50 milliseconds script will wait to CTRL press. Example 60 means 60*50=3000, so script will wait 3000 milliseconds (1sec=1000 milliseconds) for CTRL press. After that time you have to press Esc again.
        {
            b := GetKeyState("LCtrl")

            if (b=1)
            {
                ExitApp
            }
            Sleep, 50
        }

    }
}

该代码应该在您的其他代码重新映射您需要的所有键之后启动。按 Esc (现在您可以释放 Esc )并在 3000 毫秒(1sec=1000 毫秒)内按 LCtrl。在那之后,您必须再次按 Esc 才能退出脚本。如果要修改时间,之后需要再次按 Esc 阅读代码中的注释。

另外,请始终使用来自http://ahkscript.org/ 的 AutoHotkey 及其文档(当前最新版本,新官网)! AutoHotkey 及其来自 autohotkey.com 的文档已过时,您在使用它们时可能会遇到一些问题!

【讨论】:

  • 您知道returnExitApp 之后是无法访问的代码吗?另外,我认为这不完全符合 OP 的要求,因为在您的示例中,必须同时按下键。相比之下,我相信 OP 希望能够通过依次键入CTRLESCCTRL 之类的组合来退出。
  • @MCL 是的,returnExitApp 之后是正确的。我没有注意,我只是在热键末尾写return
  • @MCL OP 说:Therefore, I would prefer a sequence of single keystrokes (not holding down any key) to exit the Autohotkey mapping, such as "Esc and then LCtrl" or "Esc, LCtrl and then again Esc"。所以明白“Esc 然后 LCtrl”对他来说是可以的。
  • @MCL 添加了版本 3。
  • @T_at'Ghent 也添加了版本 3。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-06
  • 2017-05-07
  • 2021-11-02
  • 2020-08-09
  • 2017-12-07
相关资源
最近更新 更多