【问题标题】:AutoHotKey - Creating state dependent hotkeysAutoHotKey - 创建状态相关的热键
【发布时间】:2015-10-10 01:55:12
【问题描述】:

是否可以使用 AutoHotKey 创建与状态相关的热键?我知道在使用 #IfWinActive 时可以在依赖状态下创建某些热键,但是在热键本身内部创建热键怎么样?

示例

F1::
    Gui, Show, center center h500 w500, Just a window
    return

    F2::
        MsgBox, 0, F2, You have pressed F2 inside the F1 hotkey
    return
return

这里的问题是F2不依赖于状态,一按就会触发。

可能的解决方案

F1::
    state := true

    Gui, Show, center center h500 w500, Just a window
    return

    #If (state = true)
    {
        F2::
            MsgBox, 0, F2, You have pressed F2 inside the F1 hotkey
        return
    }

    GUIclose:
        Gui, destroy
        state := false
    return
return

这是一个可能的解决方案,效果很好。但是,有没有比这种方式更简单的解决方案?

【问题讨论】:

  • 据我所知,没有更好的方法。我会说你几乎把它钉牢了,代码看起来很干净。干得好。

标签: state autohotkey hotkeys


【解决方案1】:

不是很“容易”,但 imo 更好看和我更喜欢的方式:

F1::
    Hotkey, F2, F2_action, ON
    Gui, Show, center center h500 w500, Just a window
return

F2_action: ; this is a label not a hotkey
    MsgBox, 0, F2, You have pressed F2 inside the F1 hotkey
return

GUIclose:
    Gui, destroy
    Hotkey, F2, F2_action, OFF
return

我在这里使用了hotkey-command,这是专门为

但是如何在热键本身内部创建热键

【讨论】:

    【解决方案2】:

    我会采用将 2 个条件添加到 #If 的方法

    F1::
        state := true
        Gui, Show, center center h500 w500, Just a window
    Return
    
    #If state and WinActive("Just a window")
        F2::MsgBox, 0, F2, You have pressed F2 inside the F1 hotkey
    #If
    

    不确定这是否是您在声明您尝试过#IfWinActive时已经排除的情况@

    【讨论】:

    • 在这种情况下,我并没有真正使用#IfWinActive,这只是我用作参考的示例。但我很欣赏你的想法:)
    猜你喜欢
    • 2018-05-25
    • 2012-10-02
    • 2018-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多