2015-07-20 46 views
2

是否可以使用AutoHotKey創建與狀態相關的熱鍵?我知道在使用#IfWinActive時,可以在依賴狀態下創建某些熱鍵,但如何在熱鍵內部創建熱鍵?AutoHotKey - 創建與狀態相關的熱鍵

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 

這是一個可能的解決方案和工作得很好。但是,有沒有比這樣做更簡單的解決方案?

+0

據我知道的,當你已經排除了,有沒有更好的辦法。我會說你幾乎已經釘上了它,代碼看起來很乾淨。做得好。 – errorseven

回答

1

不是很「容易」,但海事組織更好看,我的首選方式:

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在這裏,這是專門爲

但如何做的在熱鍵內創建熱鍵本身

+0

也適用,謝謝你的貢獻:) – Dean

1

我會去添加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

+0

在這種情況下,我並沒有真正使用#IfWinActive,這只是我用作參考的一個例子。但我很欣賞你的想法:) – Dean