Sign in to follow this  
Followers 0
Errors4l

Newbie question - Unlisted delay after a loop

7 posts in this topic

Hello, I'm trying to get something pretty simple done with AutoIt.

While you hold down the A or D key, it loops pressing the 7, 8, 9 and 10 key, while you hold the E key it loops pressing the 4, 5 and 6 key and while you're not holding down any of those keys, it loops pressing the 1, 2 and 3 key (and pressing 2 after 3 again).

My problem is that after any of these loops are completed, instead of instantly repeating the loop it, there's about a half to a second of delay between them. How do I fix this? :/

Here's my code:

#include <Misc.au3>

While 1
If _IsPressed("41") or _IsPressed("44") Then
 Send( "7" )
 Sleep(76)
 Send( "8" )
 Sleep(76)
 Send( "9" )
 Sleep(76)
 Send( "10" )
ElseIf _IsPressed("45") Then
 Sleep(76)
 Send( "4" )
 Sleep(76)
 Send( "5" )
 Sleep(76)
 Send( "6" )
Else
 Sleep(76)
 Send( "1" )
 Sleep(76)
 Send( "2" )
 Sleep(76)
 Send( "3" )
 Sleep(76)
 Send( "2" )
EndIf
WEnd

Share this post


Link to post
Share on other sites



Hi,

Welcome to the autoit forum :)

What are you trying to achieve ? There may be more reliable ways ;)

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Thank you.

Basically, based on the keypress I want it to rotate images (it does this when you press a button from 0 to 9), which each group of actions forming sort of a mini gif.

It's a bit hard to explain, but as long as I can get rid of this delay between the loop repeating itself and checking for what keys I'm holding it'll work fine.

I did notice a mistake I made, where I put Send("10") rather than Send("0"), fixed this in my script, but it doesn't affect the issue

Share this post


Link to post
Share on other sites

Errors4l,

I get no delay when I run your code - all the returns are 0 for me. :)

#include <Misc.au3>

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

$iTimer_End = 0
$nBegin = TimerInit()

While 1
    $iTimer_Start = Int(TimerDiff($nBegin))
    If $iTimer_End <> 0 Then
        ConsoleWrite("Delay: "  & $iTimer_Start - $iTimer_End & @CRLF)
    EndIf
    $nBegin = TimerInit()
    If _IsPressed("41" & @CRLF) Or _IsPressed("44" & @CRLF) Then
        ConsoleWrite("7" & @CRLF)
        Sleep(76)
        ConsoleWrite("8" & @CRLF)
        Sleep(76)
        ConsoleWrite("9" & @CRLF)
        Sleep(76)
        ConsoleWrite("0" & @CRLF)
    ElseIf _IsPressed("45" & @CRLF) Then
        Sleep(76)
        ConsoleWrite("4" & @CRLF)
        Sleep(76)
        ConsoleWrite("5" & @CRLF)
        Sleep(76)
        ConsoleWrite("6" & @CRLF)
    Else
        Sleep(76)
        ConsoleWrite("1" & @CRLF)
        Sleep(76)
        ConsoleWrite("2" & @CRLF)
        Sleep(76)
        ConsoleWrite("3" & @CRLF)
        Sleep(76)
        ConsoleWrite("2" & @CRLF)
    EndIf
    $iTimer_End = Int(TimerDiff($nBegin))
WEnd

Func On_Exit()
    Exit
EndFunc
Try running this code on your machine and see what you get. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ahh nevermind, I figured out what I did wrong.

I made a copy of the file as it wasn't working and changes some lines, in the original broken version I had added an If WinActivate function, but put it inside the loop rather than at the beginning of the code. That was the cause of this unexpected delay.

It works now, but thanks for the help Melba23.

Your code doesn't seem to work for me at all though, as it's not sending any keypresses whether I hold down one of the keys or not (both in the program I needed this script for and testing it in an empty text file, but since I got my script to work now it doesn't really matter :o.

Anyways, sorry for the trouble!

Edited by Errors4l

Share this post


Link to post
Share on other sites

Errors4l,

 

it's not sending any keypresses

Seeing as I had replaced all the Send commands with ConsoleWrite I am not surprised in the slightest! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Share this post


Link to post
Share on other sites

Haha I guess, I blindly assumed it did the same thing (like the thread title says, not experienced with AutoIt here).

Anyways, feel free to close the thread ;)

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