Sign in to follow this  
Followers 0
will88

Register/Un-Register Hotkey

3 posts in this topic

#1 ·  Posted (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.

#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 by will88

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Something like this maybe? :lmao:

$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 :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0