dw0914 Posted September 21, 2019 Share Posted September 21, 2019 Hi all, New AutoIt user here. With the help of the FAQ, the Wiki, and a few great forum threads, I've gotten the guts of my function to do what I want it to do, which is press a key until a pixel changes to a certain color, with a random delay between key presses. Here is an example below: Func Check1 () Do Send ( "{ENTER}" ) $delay = Random(0,10000) Sleep($delay) Until PixelGetColor(1,1) = 1758338 Endfunc Now let's say I have 3 of these Check functions, each pointing to different pixels and different colors, and I want to map them all to hotkeys that I can use while the script runs persistently until I hit a termination hotkey. Here is what I was planning to add, in addition to the Check functions: HotKeySet("{ESC}", "Terminate") HotKeySet("v", "Check1") HotKeySet("b", "Check2") HotKeySet("n", "Check3") ;Check function definitions Func Terminate() Exit EndFunc While 1 Sleep(3000) Wend What I expect this to do: map the V, B, and N keys to run through Check1, Check2, and Check3 respectively, on demand, until I hit Escape which will stop the script. Here are my questions: I've read that having a Sleep in the While 1... loop can help to prevent the script from hogging CPU resources. Will having a Sleep there interfere with my ability to use the hotkeys (V, B, N) on demand, or do the hotkey binds remain -- and allow processing the Check functions on demand as well -- even with that Sleep command? Is there a different value recommended? I set it to 3 seconds of sleep. My hardware is solid, but I still don't want this script to hog resources. Does the answer about Sleep interference change if I add a timeout check to each of my "Check" functions? I was thinking of adding something like this into the Check functions: Func Check1 () $timelim = 5000 $timestart = @Sec do If @Sec > ($timestart + $timelim) Then ExitLoop EndIf ;... rest of function definition Until PixelGetColor(1,1) = 1758338 Endfunc ...I guess I'm hoping that the ExitLoop will only exit the Do...Until loop, but not the overall While 1 loop. Thank you for any advice you can offer! Link to comment Share on other sites More sharing options...
Nine Posted September 21, 2019 Share Posted September 21, 2019 (edited) 1 hour ago, dw0914 said: Will having a Sleep there interfere with my ability to use the hotkeys (V, B, N) on demand No, hotkey will trigger the function immediately 1 hour ago, dw0914 said: Is there a different value recommended? I set it to 3 seconds of sleep Doesn't matter it could be 10,100,1000... While 1...Wend uses close to 0 ressource. So you'll be in sleep all the time. 1 hour ago, dw0914 said: I was thinking of adding something like this into the Check functions No need for that, but if you want to check some form of delay use TimerInit and TimerDiff functions. May I ask what application you want to automate ? PixelGetColor is not the most robust approach to use... Edited September 21, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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