Jump to content

How run a script for a defined amount of time?


Recommended Posts

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 :) 

 

Link to comment
Share on other sites

Did you have a look at functions TimerInit/TimerDiff ?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

  • Moderators

@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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...