Sign in to follow this  
Followers 0
jops1987

Script loop try to Stop it with button but dont work

9 posts in this topic

#1 ·  Posted (edited)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$test = GUICreate("test", 193, 162, 580, 338, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
GUISetFont(8, 400, 0, "Microsoft Sans Serif")
GUISetBkColor(0xFFFFFF)
$startbutton = GUICtrlCreateButton("START", 8, 135, 75, 25)
$stopbutton = GUICtrlCreateButton("STOP", 112, 135, 75, 25)
$Label0 = GUICtrlCreateLabel("test", 8, 8, 189, 17)
$Label2 = GUICtrlCreateLabel("number", 69, 35, 53, 17)
$Label3 = GUICtrlCreateLabel("Delay", 82, 82, 101, 17)
$Delay = GUICtrlCreateInput("", 37, 95, 121, 21)
$number = GUICtrlCreateInput("", 37, 48, 121, 21, $ES_NUMBER)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select

       Case $msg = $startbutton

 If WinExists("notepad") Then
                WinActivate("notepad")
                $num = GUICtrlRead($number)
                $sleep = GUICtrlRead($Delay)
            While 1
                Send($num)
                Sleep($sleep)
             WEnd
          Else
                MsgBox(1, "Error!", "notepad is not running!")
             EndIf

        Case $msg = $stopbutton
            Exit

        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit

    EndSelect

WEnd

Any advice will be appreciate :)

Edited by jops1987

Share this post


Link to post
Share on other sites



I made some improvements with the notepad conditional, and the stop button works now.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$test = GUICreate("test", 193, 162, 580, 338, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS))
GUISetFont(8, 400, 0, "Microsoft Sans Serif")
GUISetBkColor(0xFFFFFF)
$startbutton = GUICtrlCreateButton("START", 8, 135, 75, 25)
$stopbutton = GUICtrlCreateButton("STOP", 112, 135, 75, 25)
$Label0 = GUICtrlCreateLabel("test", 8, 8, 189, 17)
$Label2 = GUICtrlCreateLabel("Number", 69, 35, 53, 17)
$Label3 = GUICtrlCreateLabel("Delay (ms)", 82, 82, 101, 17)
$Delay = GUICtrlCreateInput("", 37, 95, 121, 21)
$number = GUICtrlCreateInput("", 37, 48, 121, 21, $ES_NUMBER)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select

        Case $msg = $startbutton

            If WinExists("[CLASS:Notepad]") Then
                WinActivate("[CLASS:Notepad]")

                _Sender()
            Else
                Run("notepad.exe")
                WinWait("[CLASS:Notepad]","")
                _Sender()

            EndIf

        Case $msg = $stopbutton
            Exit

        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exit

    EndSelect

WEnd

Func _Sender()
    WinActivate("[CLASS:Notepad]")
    $num = GUICtrlRead($number)
    $sleep = GUICtrlRead($Delay)
    While 1
        Send($num)
        For $i = 0 To $sleep / 100
            Sleep(Floor($sleep / 100))
            $nMsg = GUIGetMsg()
            If $nMsg = $stopbutton Then Exit
        Next
    WEnd
EndFunc   ;==>_Sender

Share this post


Link to post
Share on other sites

thx for fast respond

Share this post


Link to post
Share on other sites

thanx that works great, however i now have a new problem.

I wan in inputbox Dealy on my gui that place a function as a sleep, so it sleeps for each number in the inputbox

can anyone give me some tips will be appreciate :)    

 

Share this post


Link to post
Share on other sites

I don't understand what you mean. Can you elaborate? 

Share this post


Link to post
Share on other sites

Well in the inputbox when someone put a number like : 123456 in each  number have a delay

Share this post


Link to post
Share on other sites

As i could understand you wana do your sleep time like = 123456 will have 6 different delay time right?

Like first number, second number ... etc?

I guess it will be bit complicate, if you can do it. Inputbox have a value what is a string or int. When you read the value, you get back the number of 123456. Better to use multiple input box for different sleeping time, or make an ini (setup) file where you can store your delay times.

Maybe someone with much more experience will come out with better solution.


Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

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