Sign in to follow this  
Followers 0
Lakes

Toggle Var with _Ispressed

1 post in this topic

Very basic script to show how to toggle a variable with _IsPressed

Press the key (1 to 6) once to change its state, then press again to change it back.

#include <GUIConstantsEx.au3>

#include <Misc.au3>

$Test = GUICreate("Toggle Test", 368, 58, 198, 124)
$TLabel4 = GUICtrlCreateLabel("Toggle4", 180, 6, 43, 17)
$TLabel3 = GUICtrlCreateLabel("Toggle3", 126, 6, 43, 17)
$TLabel2 = GUICtrlCreateLabel("Toggle2", 74, 6, 43, 17)
$TLabel5 = GUICtrlCreateLabel("Toggle5", 235, 6, 43, 17)
$TLabel1 = GUICtrlCreateLabel("Toggle1", 18, 6, 43, 17)
$TLabel6 = GUICtrlCreateLabel("Toggle6", 293, 6, 43, 17)

$LTog6 = GUICtrlCreateLabel("", 298, 32, 34, 17)
$LTog5 = GUICtrlCreateLabel("", 238, 32, 34, 17)
$LTog4 = GUICtrlCreateLabel("", 185, 32, 34, 17)
$LTog3 = GUICtrlCreateLabel("", 129, 32, 34, 17)
$LTog2 = GUICtrlCreateLabel("", 79, 32, 34, 17)
$LTog1 = GUICtrlCreateLabel("", 21, 32, 34, 17)

GUISetState(@SW_SHOW)


Global $user32_dll = DllOpen("user32.dll")
Global $Tog, $Tog1 = False, $Tog2 = $Tog1, $Tog3 = $Tog1, $Tog4 = $Tog1, $Tog5 = $Tog1, $Tog6 = $Tog1, $Delay


$Delay = 100
    Do
        $msg = GUIGetMsg()
Select
    Case _IsPressed("31", $user32_dll)  ; "1" Key
        GUICtrlSetData ( $LTog1, $Tog1 )
        $Tog1 = NOT $Tog1
        Sleep($Delay)

    Case _IsPressed("32",$user32_dll)
        GUICtrlSetData ( $LTog2, $Tog2 )
        $Tog2 = NOT $Tog2
        Sleep($Delay)

    Case _IsPressed("33",$user32_dll)
        GUICtrlSetData ( $LTog3, $Tog3 )
        $Tog3 = NOT $Tog3
        Sleep($Delay)

    Case _IsPressed("34", $user32_dll)
        GUICtrlSetData ( $LTog4, $Tog4 )
        $Tog4 = NOT $Tog4
        Sleep($Delay)

    Case _IsPressed("35", $user32_dll)
        GUICtrlSetData ( $LTog5, $Tog5 )
        $Tog5 = NOT $Tog5
        Sleep($Delay)

    Case _IsPressed("36", $user32_dll)
        GUICtrlSetData ( $LTog6, $Tog6 )
        $Tog6 = NOT $Tog6
        Sleep($Delay)
EndSelect


Sleep(10)
    Until $msg = $GUI_EVENT_CLOSE
        DllClose($User32_dll)

2015 - Still no flying cars, instead blankets with sleeves.

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