will88 Posted January 20, 2009 Share Posted January 20, 2009 (edited) Is there a simpler way of writing this other than having 2 While Loops? What it does is, when the Gui is not active, it un-registers the hot key to prevent it from interfering with other things. And when the GUI is active, it will register the hot key. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate($Main_Title,500,500) GUISetState(@SW_SHOW,$Main_Title) Dim $Save $Main_Title=":Will88::" Loop1() Func Loop1() HotKeySet("{Home}","Save") While 1 If Not WinActive($Main_Title) Then Loop2() EndIf $msg = GUIGetMsg() If $msg = -3 Then Exit If $Save=1 Then MsgBox(0,"","Save") $Save=0 EndIf WEnd EndFunc Func Loop2() HotKeySet("{Home}") While 1 If WinActive($Main_Title) Then Loop1() EndIf $msg = GUIGetMsg() If $msg = -3 Then Exit Sleep(1000) WEnd EndFunc Func Save() $Save=1 EndFunc Yeah I know its not that organized Edited January 20, 2009 by will88 Password-Keeper Link to comment Share on other sites More sharing options...
monoceres Posted January 20, 2009 Share Posted January 20, 2009 (edited) Something like this maybe? $hwnd = GUICreate("Test") GUISetState() HotKeySet("{Home}", "hkeyfunc") Global $HotkeyIsActive = True While GUIGetMsg() <> -3 $active = WinActive($hwnd) If Not $active And $HotkeyIsActive Then HotKeySet("{home}") $HotkeyIsActive = False ElseIf $active And Not $HotkeyIsActive Then HotKeySet("{home}", "hkeyfunc") $HotkeyIsActive = True EndIf WEnd Func hkeyfunc() MsgBox(0, "", "I'm active!") EndFunc ;==>hkeyfunc Edited January 20, 2009 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
will88 Posted January 20, 2009 Author Share Posted January 20, 2009 Something like this maybe? $hwnd = GUICreate("Test") GUISetState() HotKeySet("{Home}", "hkeyfunc") Global $HotkeyIsActive = True While GUIGetMsg() <> -3 $active = WinActive($hwnd) If Not $active And $HotkeyIsActive Then HotKeySet("{home}") $HotkeyIsActive = False ElseIf $active And Not $HotkeyIsActive Then HotKeySet("{home}", "hkeyfunc") $HotkeyIsActive = True EndIf WEnd Func hkeyfunc() MsgBox(0, "", "I'm active!") EndFunc ;==>hkeyfunc Thanks works great Password-Keeper 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