Errors4l Posted April 27, 2014 Share Posted April 27, 2014 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 More sharing options...
FireFox Posted April 27, 2014 Share Posted April 27, 2014 Hi, Welcome to the autoit forum What are you trying to achieve ? There may be more reliable ways Br, FireFox. Link to comment Share on other sites More sharing options...
Errors4l Posted April 27, 2014 Author Share Posted April 27, 2014 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 More sharing options...
Moderators Melba23 Posted April 27, 2014 Moderators Share Posted April 27, 2014 Errors4l,I get no delay when I run your code - all the returns are 0 for me. expandcollapse popup#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 EndFuncTry 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Solution Errors4l Posted April 27, 2014 Author Solution Share Posted April 27, 2014 (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 . Anyways, sorry for the trouble! Edited April 27, 2014 by Errors4l Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 27, 2014 Moderators Share Posted April 27, 2014 Errors4l, it's not sending any keypressesSeeing as I had replaced all the Send commands with ConsoleWrite I am not surprised in the slightest! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Errors4l Posted April 27, 2014 Author Share Posted April 27, 2014 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now