Sign in to follow this  
Followers 0
TokeySmurf

Problems With Loop

5 posts in this topic

#1 ·  Posted (edited)

It only exectues once, the buttons still seem functional but the actual loop doesn't work

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICoordMode", 1)
Opt("WinTitleMatchMode", 4)

Global $Show = 0
Global $handle = WinGetHandle("classname=GxWindowClassD3d")
If @error Then
    MsgBox(0, "Blank Not Found", "Please Start Blank")
    Exit
EndIf

$mainwindow = GUICreate("Blank", 200, 100)
$startb = GUICtrlCreateButton("Start",25,50,70,25) 
GUICtrlSetOnEvent($startb, "Start")
$Stopb = GUICtrlCreateButton("Stop",100 ,50,70,25 )
GUICtrlSetOnEvent($Stopb, "Stop")
$hStatus = GUICtrlCreateLabel("", 10, 25, 200, 20)
GUISetState(@SW_SHOW)
WinSetState($handle, "", @SW_RESTORE)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
WinSetOnTop($mainwindow, "", 1)
GUICtrlSetData($hStatus,"Status: Click Start to Begin!")

While 1
    Sleep(20)
    
    If $Show = 1 Then 
        ControlSend($handle, "", "", "{UP DOWN}")
        Sleep(100)
        ControlSend($handle, "", "", "{UP UP}")
        ControlSend($handle, "", "", "{DOWN DOWN}")
        Sleep(100)
        ControlSend($handle, "", "", "{DOWN UP}")
        Sleep(200000)
         $Show = 0
    EndIf
WEnd

Func Start()
    
  ;WinSetState($handle, "", @SW_MINIMIZE)
  ;WinSetState ($handle, "", @SW_HIDE )
    If @error Then
        MsgBox(0, "Blank2 Not Found", "Please Start Blank2", 3)
    Else
        GUICtrlSetData($hStatus,"Status: Blank Started")
        $Show = 1
    EndIf
EndFunc ;==>Start

    func Stop() 
    If $Show = 1 Then
        WinSetState($handle, "", @SW_SHOW)
        WinSetState($handle, "", @SW_RESTORE)
        WinActivate($handle, "")
        GUICtrlSetData($hStatus,"Status: Blank Halted")
        $Show = 0
    Else
        GUICtrlSetData($hStatus,"Status: 'ERROR' Blank Not Running")
        $Show = 0
    EndIf
    EndFunc

Func CLOSEClicked()
   GUICtrlSetData($hStatus,"Status: Closing.. Have a nice day!")
    Exit
EndFunc ;==>CLOSEClicked
Edited by TokeySmurf

Share this post


Link to post
Share on other sites



Well, you never make $show = 1 again :)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Well, you never make $show = 1 again :)

Would I do it here?

While 1
    Sleep(20)
    
    If $Show = 1 Then
        ControlSend($handle, "", "", "{UP DOWN}")
        Sleep(100)
        ControlSend($handle, "", "", "{UP UP}")
        ControlSend($handle, "", "", "{DOWN DOWN}")
        Sleep(100)
        ControlSend($handle, "", "", "{DOWN UP}")
        Sleep(200000)
        $Show = 1   <--- here?
    EndIf
WEnd

Share this post


Link to post
Share on other sites

Would I do it here?

While 1
    Sleep(20)
    
    If $Show = 1 Then
        ControlSend($handle, "", "", "{UP DOWN}")
        Sleep(100)
        ControlSend($handle, "", "", "{UP UP}")
        ControlSend($handle, "", "", "{DOWN DOWN}")
        Sleep(100)
        ControlSend($handle, "", "", "{DOWN UP}")
        Sleep(200000)
        $Show = 1   <--- here?
    EndIf
WEnd
I'm really confused now.. As the msgs change (halt start stop etc) but the loop just wont start back up no matter if you hit stop then start or what.. I don't get it

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try this:

CODE
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Opt("GUICoordMode", 1)

Opt("WinTitleMatchMode", 4)

Global $Show

Global $handle = WinGetHandle("classname=GxWindowClassD3d")

If @error Then

MsgBox(0, "Blank Not Found", "Please Start Blank")

Exit

EndIf

$mainwindow = GUICreate("Blank", 200, 100)

$startb = GUICtrlCreateButton("Start",25,50,70,25)

GUICtrlSetOnEvent($startb, "Start")

$Stopb = GUICtrlCreateButton("Stop",100 ,50,70,25 )

GUICtrlSetOnEvent($Stopb, "Stop")

$hStatus = GUICtrlCreateLabel("", 10, 25, 200, 20)

GUISetState(@SW_SHOW)

WinSetState($handle, "", @SW_RESTORE)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

WinSetOnTop($mainwindow, "", 1)

GUICtrlSetData($hStatus,"Status: Click Start to Begin!")

While 1

Sleep(20)

If $Show Then

ControlSend($handle, "", "", "{UP DOWN}")

Sleep(100)

ControlSend($handle, "", "", "{UP UP}")

ControlSend($handle, "", "", "{DOWN DOWN}")

Sleep(100)

ControlSend($handle, "", "", "{DOWN UP}")

Sleep(200000)

;$Show = Not $Show ; Only use this one if you want the loop to run 1 time, if you want it to run until you press stop then keep it commented or remove it.

EndIf

WEnd

Func Start()

;WinSetState($handle, "", @SW_MINIMIZE)

;WinSetState ($handle, "", @SW_HIDE )

If @error Then

MsgBox(0, "Blank2 Not Found", "Please Start Blank2", 3)

Else

GUICtrlSetData($hStatus,"Status: Blank Started")

$Show = Not $Show

EndIf

EndFunc ;==>Start

func Stop()

$Show = Not $Show

If $Show Then

WinSetState($handle, "", @SW_SHOW)

WinSetState($handle, "", @SW_RESTORE)

WinActivate($handle, "")

GUICtrlSetData($hStatus,"Status: Blank Halted")

$Show = Not $Show

Else

GUICtrlSetData($hStatus,"Status: 'ERROR' Blank Not Running")

$Show = Not $Show

EndIf

EndFunc

Func CLOSEClicked()

GUICtrlSetData($hStatus,"Status: Closing.. Have a nice day!")

Exit

EndFunc ;==>CLOSEClicked

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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