jannikrendl

How run a script for a defined amount of time?

7 posts in this topic

#1 ·  Posted

Hey guys,

I was trying to create a script which runs for a specified/defined amount of time but I dont know how to do that. I also would like to add a GUI where I can define the amount of time.

Would be nice if someone could help me...

Thanks in advance

Jannik Rendl :) 

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Did you have a look at functions TimerInit/TimerDiff ?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

jannikrendle,

Something to get you started...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <editconstants.au3>

Local $mygui = GUICreate('Test Gui', 300, 70)
GUICtrlCreateLabel('Second to Run GUI', 10, 13, 100, 20)
Local $mytime = GUICtrlCreateInput('', 110, 10, 20, 20, $ES_NUMBER)
Local $start = GUICtrlCreateButton('Start Timer', 190, 10, 100, 20)
GUICtrlSetLimit(-1, 2)
Local $status = GUICtrlCreateLabel('', 10, 40, 280, 20, BitOR($SS_SUNKEN, $SS_CENTER))
GUICtrlSetColor($status, 0xff0000)
GUICtrlSetFont($status, 10, 800)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
        Case $mytime
            ;
            ; if you want to do something with the input value do it here
            ;
        Case $start
            $timer = TimerInit()
            chk_time()
            AdlibRegister('chk_time', 1000)
            GUICtrlSetState($mytime, $GUI_DISABLE)
            GUICtrlSetState($start, $GUI_DISABLE)
    EndSwitch
WEnd

Func chk_time()

    Local $diff = Int(TimerDiff($timer))
    If $diff > GUICtrlRead($mytime) * 1000 Then Exit MsgBox(0, '$$$$$$$$$$', 'Quitting', 2)
    GUICtrlSetData($status, 'Quitting in ' & GUICtrlRead($mytime) - Int($diff / 1000) & ' Seconds')

EndFunc   ;==>chk_time

Note - one of many ways to do this...also, this is just an example.  How you calc the time will depend on factors you have not given.

kylomas

Edited by kylomas
3 people like this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi jannikrendl,

Try this:

Local $Shell = ObjCreate("shell.application")
Global $tots
$TimeInput = InputBox("AutoTimeCount", "Enter your specified time(minutes): ")

$tots = $TimeInput * 60
$tots = $tots * 1000

sleep($tots)
Send("{ENTER}")

This is to automatically hit enter based on your input desired/specified amount of time. If you wan't to have it in seconds count, change "$tots * 60" to "$tots * 10" and "$tots * 1000" to "$tots * 100".

Or if you don't wan't to hit enter automatically try below:

Local $Shell = ObjCreate("shell.application")
Global $tots
$TimeInput = InputBox("AutoTimeCount", "Enter your specified time(minutes): ")

$tots = $TimeInput * 60
$tots = $tots * 1000

sleep($tots)
; do something here...

Hope I've understand your problem correctly.:sweating:

 

KS15

Edited by KickStarter15
1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

8 hours ago, kylomas said:

jannikrendle,

Something to get you started...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <editconstants.au3>

Local $mygui = GUICreate('Test Gui', 300, 70)
GUICtrlCreateLabel('Second to Run GUI', 10, 13, 100, 20)
Local $mytime = GUICtrlCreateInput('', 110, 10, 20, 20, $ES_NUMBER)
Local $start = GUICtrlCreateButton('Start Timer', 190, 10, 100, 20)
GUICtrlSetLimit(-1, 2)
Local $status = GUICtrlCreateLabel('', 10, 40, 280, 20, BitOR($SS_SUNKEN, $SS_CENTER))
GUICtrlSetColor($status, 0xff0000)
GUICtrlSetFont($status, 10, 800)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
        Case $mytime
            ;
            ; if you want to do something with the input value do it here
            ;
        Case $start
            $timer = TimerInit()
            chk_time()
            AdlibRegister('chk_time', 1000)
            GUICtrlSetState($mytime, $GUI_DISABLE)
            GUICtrlSetState($start, $GUI_DISABLE)
    EndSwitch
WEnd

Func chk_time()

    Local $diff = Int(TimerDiff($timer))
    If $diff > GUICtrlRead($mytime) * 1000 Then Exit MsgBox(0, '$$$$$$$$$$', 'Quitting', 2)
    GUICtrlSetData($status, 'Quitting in ' & GUICtrlRead($mytime) - Int($diff / 1000) & ' Seconds')

EndFunc   ;==>chk_time

Note - one of many ways to do this...also, this is just an example.  How you calc the time will depend on factors you have not given.

kylomas

Hey kylomas,

I changed a bit of your code/script and the main parts work. So I tried to create a "Stop" button... I created it and gave it the right command to quit the script but it won't stop the script...

Need some more help sry :/

Thanks in advance

Jannik Rendl

 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <editconstants.au3>

Local $mygui = GUICreate('AlphaSpan.exe', 300, 70)
GUICtrlCreateLabel('Runtime in minutes:', 10, 13, 100, 20)
Local $mytime = GUICtrlCreateInput('', 110, 10, 40, 20, $ES_NUMBER)
Local $start = GUICtrlCreateButton('Start', 160, 10, 60, 20)
Local $stop = GUICtrlCreateButton('Stop', 230, 10, 60, 20)
GUICtrlSetLimit(-1, 2)
Local $status = GUICtrlCreateLabel('', 10, 40, 280, 20, BitOR($SS_SUNKEN, $SS_CENTER))
GUICtrlSetColor($status, 0xff0000)
GUICtrlSetFont($status, 10, 800)

GUISetState()

Global $harvesting = False

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
        Case $mytime
        Case $start
            $timer = TimerInit()
            Do
                Sleep(100)
                AlphaSpan()
            Until chk_time()
                AdlibRegister('chk_time', 1000)
                GUICtrlSetState($mytime, $GUI_DISABLE)
                GUICtrlSetState($start, $GUI_DISABLE)
        Case $stop
            Exit
    EndSwitch
WEnd

Func chk_time()
    Local $diff = Int(TimerDiff($timer))
    If $diff > GUICtrlRead($mytime) * 1000 * 60 Then Exit MsgBox(0, 'AlphaSpan.exe', 'Thanks for using AlphaSpan. See you soon...', 10)
    GUICtrlSetData($status, 'Ending in ' & GUICtrlRead($mytime) - Int($diff / 1000 / 60) & ' Minutes')
EndFunc

Func AlphaSpan()
    WinActivate("RuneScape")
    $pixWolke = PixelSearch(7,245,957,981,0x1A1227,2)
        If not(@error) Then
            MouseClick("Left",$pixWolke[0],$pixWolke[1],1,8)
            $harvesting = True
            Sleep(8000)
                While($harvesting)
                    PixelSearch(482,56,476,50,0xFBE583,2)
                        If Not(@error) Then
                        Else
                            $harvesting = False
                        EndIf
                WEnd
        Else
            $pixFeuer = PixelSearch(7,245,957,981,0xCD1F0A,2)
                If not(@error) Then
                    MouseClick("Left",$pixFeuer[0],$pixFeuer[1],1,8)
                    $harvesting = True
                    Sleep(8000)
                        While($harvesting)
                            PixelSearch(482,56,476,50,0xFBE583,2)
                                If Not(@error) Then
                                Else
                                    $harvesting = False
                                EndIf
                        WEnd
                Else
                    $pixHund = PixelSearch(7,245,957,981,0x545CCE,2)
                        If not(@error) Then
                            MouseClick("Left",$pixHund[0],$pixHund[1],1,8)
                            $harvesting = True
                            Sleep(8000)
                                While($harvesting)
                                    PixelSearch(482,56,476,50,0xFBE583,2)
                                        If Not(@error) Then
                                        Else
                                            $harvesting = False
                                        EndIf
                                WEnd
                        Else
                        EndIf
                EndIf
        EndIf

EndFunc

 

Edited by jannikrendl

Share this post


Link to post
Share on other sites

#6 ·  Posted

52 minutes ago, jannikrendl said:

WinActivate("RuneScape")

 

What exactly is the purpose of your script?


Taken from the forum rules:
 

Quote

1. Do not ask for help with AutoIt scripts, post links to, or start discussion topics on the following subjects:

  • Launching, automation or script interaction with games or game servers, regardless of the game.
1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted

@jannikrendl Floops is quite right. Given the Runescape window and your variables of $harvesting, please familiarize yourself with the forum rules before you post again. Hope to see you soon with a legitimate question.

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.