Jump to content

Timer Without Using Sleep


Recommended Posts

I want to create a script where a arrow keys a press with delays for how long its held and when to press them.

E.G

Script Started

Up arrow held down >

Wait 500 >

Left Arrow held down >

Wait 250 >

Left Arrow Up >

Script Stopped

I've tried it using Sleep(100), but it doesn't keep the Up arrow held down constantly as it pause the script. Not delay an action.

Thanks

Flemingjp

Link to comment
Share on other sites

  • Developers

Should work fine when done correctly.... post your script to see what you are doing.

By the way, welcome and hope you did take the time to read our forum rules.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

MouseClick("Left", 300, 350, 1, 5)
sleep(2990)
Send("{UP down}")
sleep(550)
Send("{LEFT down}")
sleep(350)
Send("{LEFT up}")

The sleep is for pausing script. It won´t work.

This is what you´re after:

#include <Timers.au3>

_Timer()

Func _Timer()

    Send("#r")
    WinWaitActive("Run")
    Send("notepad.exe{Enter}")
    WinWaitActive("[CLASS:Notepad]")
    
    Global $starttime = _Timer_Init()
    
    While _Timer_Diff($starttime)<1000
        Send("Hello ... Is just an example")
        
    WEnd
EndFunc   ;==>_Timer
Edited by realshyfox

Learn, learn and ... learn

Link to comment
Share on other sites

  • Developers

The sleep is for pausing script. It won´t work.

It works fine to keep the KeyDown, but it will not repeatedly press it.

Slight difference here :huh2:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

It works fine to keep the KeyDown, but it will not repeatedly press it.

Slight difference here :huh2:

Well, let´s change a little:

#include <Timers.au3>

_Timer()

Func _Timer()

    Send("#r")
    WinWaitActive("Run")
    Send("notepad.exe{Enter}")
    WinWaitActive("[CLASS:Notepad]")
    
    Global $starttime = _Timer_Init()
    
    While _Timer_Diff($starttime)<5000
        Send("Hello ... Is just an example")
        Sleep(500)
    $iIdleTime = _Timer_GetIdleTime()
    $starttime = $starttime + $iIdleTime
    WEnd
EndFunc   ;==>_Timer
Edited by realshyfox

Learn, learn and ... learn

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

  • Recently Browsing   0 members

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