Jump to content

Recommended Posts

Posted

Hello,

i am having problems with this section of code and involves timerinit function call...i dont know what am i doing wrong.

$timer_1    =   _Timer_Init()
$timer_2    =   _Timer_Init()

local $timer11 = 10000,$var1,$var2
local $timer21 = 10000


While 1


Sleep(100)
    
    Call("function1")
    
Sleep(100)  
    
    Call("function2")

local $dif1 = _Timer_Diff($timer_1)

if $dif1 > $timer11*1000  then    
        
        if $var1 = 1 Then
            $timer_1=0
            $timer_1 = _Timer_Init()
            call("function3")
        EndIf
    EndIf

local $dif2 =   _Timer_Diff($timer_2)

if $dif2 > $timer21*1000  then    
        
        if $var2 = 1 Then
            $timer_2=0
            $timer_2 = _Timer_Init()
            call("function3")
        EndIf
    EndIf
    
WEnd

Next thing i would like to ask is this (see code example below):

ControlSend("Program", "", "", "+3")

I was wondering if its possible to send shift key to an inactive window like that?

I tied it and it doesnt work somehow and i want to know if its a shift problem so i

can start looking for other solutions.

Thank you!

  • Moderators
Posted

amakrkr,

Not sure you have quite got the hang of the timers yet! :P

For simple timings like this, just use the built-in Timer commands. Then you need to think about the timimgs im milliseconds - at one point you were waiting for 1000000 msecs, i.e. 16.666666 minutes. :( Did you really want to wait this long?

And why were you using Call for the function calls? Just use the function name. :lol:

I have trimmed down the code and I hope it shows you how the timers work. You can follow the script by looking in the SciTE console:

HotKeySet("{ESC}", "On_Exit")

Func On_Exit()
    Exit
EndFunc

$timer_1 = TimerInit()
$timer_2 = TimerInit()

Global  $timer11 = 10000 ; 10 seconds
Global  $timer21 = 5000  ; 5 seconds

Global $var1 = 1, $var2 =1

While 1

    Sleep(1000)

    function1()

    Sleep(1000)

    function2()

    If  TimerDiff($timer_1) > $timer11 Then

        If $var1 = 1 Then
            $timer_1 = TimerInit()
            function3()
        EndIf
    EndIf

    If TimerDiff($timer_2) > $timer21 Then

        If $var2 = 1 Then
            $timer_2 = TimerInit()
            function4()
        EndIf
    EndIf

WEnd

Func function1()
    ConsoleWrite("Function 1 - " & @SEC & @CRLF)
EndFunc

Func function2()
    ConsoleWrite("Function 2 - " & @SEC & @CRLF)
EndFunc

Func function3()
    ConsoleWrite("Function 3 - " & @SEC & " - every " & $timer11/ 1000 & " secs" & @CRLF)
EndFunc

Func function4()
    ConsoleWrite("Function 4 - " & @SEC & " - every " & $timer21/ 1000 & " secs" & @CRLF)
EndFunc

You will see that Functions 3 & 4 sometimes fire a bit over the 5 and 10 seconds set. That is because they must wait until Functions 1 & 2 and the 2 Sleep commands finish. If you want functions to run exactly at the specified time you need to look at AdlibRegister, but we will leave that until another day!

I hope that makes it clearer - please ask if you still have questions. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

i am having problems with this section of code and involves timerinit function call...i dont know what am i doing wrong.

I don't see the point of it. What was it supposed to do, and what did it do instead?

Next thing i would like to ask is this (see code example below):

ControlSend("Program", "", "", "+3")

I was wondering if its possible to send shift key to an inactive window like that?

I tied it and it doesnt work somehow and i want to know if its a shift problem so i

can start looking for other solutions.

This seems to work fine:
Run("notepad.exe", "", @SW_MINIMIZE)
WinWait("Untitled - Notepad")
$hWin = WinGetHandle("Untitled - Notepad")
ControlSend($hWin, "", "Edit1", "+3")

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

amakrkr,

Not sure you have quite got the hang of the timers yet! :P

For simple timings like this, just use the built-in Timer commands. Then you need to think about the timimgs im milliseconds - at one point you were waiting for 1000000 msecs, i.e. 16.666666 minutes. :( Did you really want to wait this long?

And why were you using Call for the function calls? Just use the function name. :lol:

I have trimmed down the code and I hope it shows you how the timers work. You can follow the script by looking in the SciTE console:

HotKeySet("{ESC}", "On_Exit")

Func On_Exit()
    Exit
EndFunc

$timer_1 = TimerInit()
$timer_2 = TimerInit()

Global  $timer11 = 10000 ; 10 seconds
Global  $timer21 = 5000  ; 5 seconds

Global $var1 = 1, $var2 =1

While 1

    Sleep(1000)

    function1()

    Sleep(1000)

    function2()

    If  TimerDiff($timer_1) > $timer11 Then

        If $var1 = 1 Then
            $timer_1 = TimerInit()
            function3()
        EndIf
    EndIf

    If TimerDiff($timer_2) > $timer21 Then

        If $var2 = 1 Then
            $timer_2 = TimerInit()
            function4()
        EndIf
    EndIf

WEnd

Func function1()
    ConsoleWrite("Function 1 - " & @SEC & @CRLF)
EndFunc

Func function2()
    ConsoleWrite("Function 2 - " & @SEC & @CRLF)
EndFunc

Func function3()
    ConsoleWrite("Function 3 - " & @SEC & " - every " & $timer11/ 1000 & " secs" & @CRLF)
EndFunc

Func function4()
    ConsoleWrite("Function 4 - " & @SEC & " - every " & $timer21/ 1000 & " secs" & @CRLF)
EndFunc

You will see that Functions 3 & 4 sometimes fire a bit over the 5 and 10 seconds set. That is because they must wait until Functions 1 & 2 and the 2 Sleep commands finish. If you want functions to run exactly at the specified time you need to look at AdlibRegister, but we will leave that until another day!

I hope that makes it clearer - please ask if you still have questions. :mellow:

M23

that was really helpful

ty again

Posted

I don't see the point of it. What was it supposed to do, and what did it do instead?

This seems to work fine:

Run("notepad.exe", "", @SW_MINIMIZE)
WinWait("Untitled - Notepad")
$hWin = WinGetHandle("Untitled - Notepad")
ControlSend($hWin, "", "Edit1", "+3")

:mellow:

thx for replay i found out the error was not in my coding but in window that is receiving keys.

thx

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
×
×
  • Create New...