PhilHibbs Posted January 6, 2010 Share Posted January 6, 2010 (edited) I have a few scripts that just sit in the background and only do something when I press a key (I usually use ` for this). What's the best way to structure this kind of script? The simplest would be like this... HotKeySet("`","Clicker") While 1 WEnd Func Clicker() MouseClick("left") MouseClick("left") EndFunc Is the empty While loop efficient? Is it going to run the CPU ragged, and if so is there a good way to make it less greedy? Edited January 6, 2010 by PhilHibbs Link to comment Share on other sites More sharing options...
GodForsakenSoul Posted January 6, 2010 Share Posted January 6, 2010 Extremely inefficient. You should be adding a sleep in there of at least 100.By the way, a sleep time of 50 milliseconds is the minimum that AutoIt accepts.i do sleep(10) and it seems to work o.O Link to comment Share on other sites More sharing options...
PhilHibbs Posted January 6, 2010 Author Share Posted January 6, 2010 (edited) i do sleep(10) and it seems to work o.OI suspect that anything less than around 55 actually sleeps for 1/18.2 of a second, or more likely a random amount of time up to that depending on when the clock last ticked. Edited January 6, 2010 by PhilHibbs Link to comment Share on other sites More sharing options...
James Posted January 6, 2010 Share Posted January 6, 2010 i do sleep(10) and it seems to work o.OSorry, you're correct, it is 10. But Sleep 10 is the same as Sleep 1. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
GodForsakenSoul Posted January 6, 2010 Share Posted January 6, 2010 I suspect that anything less than around 55 actually sleeps for 1/18.2 of a second, or more likely a random amount of time up to that depending on when the clock last ticked.i'm slightly interested in where the hell did you come up with the number Link to comment Share on other sites More sharing options...
KaFu Posted January 6, 2010 Share Posted January 6, 2010 By the way, a sleep time of 50 milliseconds is the minimum that AutoIt accepts. Isn't it 10 ms? $time = "" $timer = TimerInit() for $i = 1 to 10 $time &= "Sleep " & $i & ": " & round(TimerDiff($timer)) & @crlf sleep(50) Next ConsoleWrite("sleep(50)" & @crlf & $time & @crlf & @crlf) $time = "" $timer = TimerInit() for $i = 1 to 10 $time &= "Sleep " & $i & ": " & round(TimerDiff($timer)) & @crlf sleep(10) Next ConsoleWrite("sleep(10)" & @crlf & $time & @crlf & @crlf) $time = "" $timer = TimerInit() for $i = 1 to 10 $time &= "Sleep " & $i & ": " & round(TimerDiff($timer)) & @crlf sleep(5) Next ConsoleWrite("sleep(5)" & @crlf & $time & @crlf & @crlf) Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 6, 2010 Share Posted January 6, 2010 Sorry, you're correct, it is 10. But Sleep 10 is the same as Sleep 1.No. 1-9 will be run as 10 link to thread about it .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
PhilHibbs Posted January 6, 2010 Author Share Posted January 6, 2010 i'm slightly interested in where the hell did you come up with the numberThe old IBM PC clock ticked 18.2 times per second. I actually don't know if that is still true on modern hardware. Link to comment Share on other sites More sharing options...
James Posted January 6, 2010 Share Posted January 6, 2010 No. 1-9 will be run as 10 link to thread about itThat's what I meant. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Mison Posted January 7, 2010 Share Posted January 7, 2010 (edited) No. 1-9 will be run as 10 link to thread about it verified. simple test: $init = TimerInit() ; warming up timer For $i = 0 To 20 $init = TimerInit() Sleep($i) $diff = Round(TimerDiff($init)) ConsoleWrite("Sleep("&$i&"); Actual sleep = "&$diff&@CRLF) Next Result: Sleep(0); Actual sleep = 0 Sleep(1); Actual sleep = 10 Sleep(2); Actual sleep = 11 Sleep(3); Actual sleep = 11 Sleep(4); Actual sleep = 11 Sleep(5); Actual sleep = 11 Sleep(6); Actual sleep = 11 Sleep(7); Actual sleep = 11 Sleep(8); Actual sleep = 12 Sleep(9); Actual sleep = 14 Sleep(10); Actual sleep = 14 Sleep(11); Actual sleep = 12 Sleep(12); Actual sleep = 21 Sleep(13); Actual sleep = 22 Sleep(14); Actual sleep = 26 Sleep(15); Actual sleep = 21 Sleep(16); Actual sleep = 21 Sleep(17); Actual sleep = 26 Sleep(18); Actual sleep = 21 Sleep(19); Actual sleep = 21 Sleep(20); Actual sleep = 26 Edited January 7, 2010 by Mison Hi ;) Link to comment Share on other sites More sharing options...
Malkey Posted January 7, 2010 Share Posted January 7, 2010 I suspect that anything less than around 55 actually sleeps for 1/18.2 of a second, or more likely a random amount of time up to that depending on when the clock last ticked. To state the obvious. Assuming sleep(1000) pauses the script execution for one second. Then, the delay parameter units, as mentioned in the help file, is in milliseconds. Therefore, sleep(55) should pause script execution for 55 milliseconds. 55 milliseconds = 55/1000 seconds = 1/18.18181818 which approx. equals 1/18.2 of a second. PhilHibbs If you do not know about how the sleep command deduces the cpu usage, then do the following test. First - Open up the Task Manager. (Right click on desktop task bar and select from menu) Select the Performance tab on Windows Task Manager window so you can see the CPU Usage display which should be on 0%. When the script is running, notice the difference how not having a sleep inside the loop over works the CPU, compared to having a sleep inside the loop. HotKeySet("`", "Clicker") HotKeySet("{ESC}", "Terminate") While 1 sleep(10) ; Comment this line out to see difference in CPU Usage. WEnd Func Clicker() MouseClick("left") MouseClick("left") EndFunc ;==>Clicker Func Terminate() Exit 0 EndFunc ;==>Terminate 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