2016-03-05 126 views
1

我試圖禁用Alt + F4,但我想啓用它時,我按Windows鍵+ Q.到目前爲止,我有這是不工作。AutoHotKey - 如何在IF語句上使用組合鍵?

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. 
; #Warn ; Enable warnings to assist with detecting common errors. 
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. 
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. 

if (#q) 
{ 
    Send !{F4} 
    Return 
} else { 
    !F4::Return 
} 
+0

@Blauhirn,我對AHK並不瞭解太多。你能舉一個例子說清楚它是如何清潔的嗎? – user400424

回答

0
; autoexecute section: 
Alt_F4_enabled:= false 
; ... 
    return ; end of autoexecute section 

#q:: Alt_F4_enabled:= true 

!F4:: 
If Alt_F4_enabled 
{ 
    Send !{F4} 
    Alt_F4_enabled:= false 
} 
else 
    return ; do nothing 
return 
+0

如果你不介意我問,那是什麼? ......在第三行呢? – user400424

+0

此外,您的代碼只是部分工作。雖然它禁用了Alt + F4,但按Win + Q不會執行Alt + F4,但在按下Win + Q後,我可以手動按Alt + F4,並且它可以再次運行而不會被阻止。 – user400424

+0

沒關係,我通過將'Send!{F4}'移動到'#q'並通過'Return'關閉了它。 – user400424

0

關於#q!F4::Return:這是沒有 commansd,他們熱鍵,因此,隱含包含return。你不能在可執行的上下文中使用它。有關詳細信息,請參閱下面的某個地方的http://ahkscript.org/docs/misc/Remap.htm#Remarks

你不希望在應該執行的行之間有一個回報,你會。

(見我的回答here

用於切換熱鍵的行動,我更喜歡使用Hotkey命令link):

hotkey, !F4, closeWindow, ON ; this is a command. "creates" a hotkey 

closeWindow: ; this is a label 
    send !{f4} 
return 

#q:: ; this is a hotkey 
    hotkey, !F4, closeWindow, TOGGLE ; this is a command. disables or enables the hotkey 
return 

這樣做,很容易動態地給!F4更功能。

代碼沒有測試

但事實上,沒有很大的原因,你不能這樣做user12344312257994344s方式。