Klovis Posted July 11, 2011 Share Posted July 11, 2011 What I want to do is have a hotkey turned on or off, so not really two hotkeys but depending on if the button says on or off I want the hotkey to be turned on or off. Here's my attempt. Mt Attempt: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("HotKeyOnOrOff", 76, 26, 192, 114) $Button1 = GUICtrlCreateButton("On", 0, 0, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### HotKeySet("a", "_main") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $r = GUICtrlRead($Button1) If $r = "On" Then GUICtrlSetData($Button1, "Off") If $r = "Off" Then GUICtrlSetData($Button1, "On") EndSwitch WEnd Func _main() If $r = "On" Then Send("a") EndIf If $r = "Off" Then Send("") EndIf EndFunc Link to comment Share on other sites More sharing options...
smartee Posted July 11, 2011 Share Posted July 11, 2011 Hi Klovis, Calling HotKeySet with no second parameter turns it off See the help-file for details -smartee Link to comment Share on other sites More sharing options...
smartee Posted July 11, 2011 Share Posted July 11, 2011 Ok here's an example #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("a", "_ConsoleW") Global $iCount = 0 #region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 250, 50) $Checkbox1 = GUICtrlCreateCheckbox("Activate HotKey", 10, 10, 230, 30) GUICtrlSetState(-1, $GUI_CHECKED) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Checkbox1 If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then HotKeySet("a", "_ConsoleW") Else HotKeySet("a") EndIf EndSwitch WEnd Func _ConsoleW() $iCount += 1 ConsoleWrite($iCount & ". You pressed the HotKey" & @CRLF) EndFunc ;==>_ConsoleW Link to comment Share on other sites More sharing options...
Klovis Posted July 11, 2011 Author Share Posted July 11, 2011 This is what I got from your reply and it doesnt work :/ #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("HotKeyOnOrOff", 76, 26, 192, 114) $Button1 = GUICtrlCreateButton("On", 0, 0, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $r = GUICtrlRead($Button1) If $r = "On" Then GUICtrlSetData($Button1, "Off") HotKeySet("a", "_main") EndIf If $r = "Off" Then GUICtrlSetData($Button1, "On") HotKeySet("a") EndIf EndSwitch WEnd Func _main() Send("a") EndFunc Link to comment Share on other sites More sharing options...
smartee Posted July 11, 2011 Share Posted July 11, 2011 Did you try the example i posted? How did that work out? don't send the key that is your hot-key without turning off your hot-key first else it will go into a recursive loop until AutoIt crashes. Link to comment Share on other sites More sharing options...
Klovis Posted July 11, 2011 Author Share Posted July 11, 2011 Sorry didnt see your reply when you posted it Link to comment Share on other sites More sharing options...
Klovis Posted July 11, 2011 Author Share Posted July 11, 2011 works good don't know much about check boxes but I'll see if I can decipher the code Link to comment Share on other sites More sharing options...
smartee Posted July 11, 2011 Share Posted July 11, 2011 Ok, here you go, I modified your code with the corrections i advised in post#5, #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> HotKeySet("a", "_main") ;On by default #region ### START Koda GUI section ### Form= $Form1 = GUICreate("HotKeyOnOrOff", 155, 45) $Button1 = GUICtrlCreateButton("On", 40, 10, 75, 25) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $r = GUICtrlRead($Button1) If $r = "On" Then GUICtrlSetData($Button1, "Off") HotKeySet("a", "_main") EndIf If $r = "Off" Then GUICtrlSetData($Button1, "On") HotKeySet("a") EndIf EndSwitch WEnd Func _main() HotKeySet("a") ;turn off hotkey before sending the same key Send("a") HotKeySet("a", "_main") ;turn it back on EndFunc ;==>_main Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now