Jump to content

Newbie question - Unlisted delay after a loop


Go to solution Solved by Errors4l,

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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

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

 

Link to comment
Share on other sites

  • Solution

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

  • Moderators

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

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

 

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