Jump to content
Sign in to follow this  
HankHell

Use a single key to toggle between functions

Recommended Posts

HankHell

hey guys, not sure if this is something that well known. I asked a question a while back to see if I could use a single hotkey as a toggle between states or functions. After not getting any replies and the topic going dead, I figured I'd post this so that others can use single hotkeys as a toggle as well.

#include <MsgBoxConstants.au3>

HotKeySet("{ESC}", "End")
HotKeySet("{F1}", "Toggle")

Global $MOUSE_CLICK_LEFT

Global $State = 1
Global $ToggleState
Global $Toggle = True

If $Toggle = False Then
   $ToggleState = True
Else
   $ToggleState = False
EndIf

While $State = 1
   Sleep(100)
WEnd

Func Toggle()
   $ToggleState = NOT $ToggleState
    While $ToggleState
        MouseClick($MOUSE_CLICK_LEFT)
    If Not $ToggleState Then
        MsgBox($MB_SYSTEMMODAL,"Notice","Macro Ended",10)
    EndIf
   WEnd
      Sleep(100)
EndFunc

Func End()
   Exit
EndFunc

and of course this also works as well...

Func Toggle()
   $ToggleState = NOT $ToggleState
   If $ToggleState Then
      MsgBox($MB_SYSTEMMODAL,"Test 1","1",10)
   Else
      MsgBox($MB_SYSTEMMODAL,"Test 2","2",10)
   EndIf
      Sleep(100)
EndFunc

 

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  

×