SMOKE1990 Posted December 18, 2011 Share Posted December 18, 2011 How can i use this script for the more accurate sleep to sleep the time in an input box this is the accurate sleep script i found If you want it even more accurate, you should to all assigning outside of the func: Func _HighPrecisionSleep(ByRef $aSleep) DllCall($aSleep[0],"dword","ZwDelayExecution","int",0,"ptr",$aSleep[2]) EndFunc Func _HighPrecisionSleep_Init($iMicroSeconds=0) Local $aSleep[3] = [DllOpen("ntdll.dll"),DllStructCreate("int64 time;")] $aSleep[2] = DllStructGetPtr($aSleep[1]) DllStructSetData($aSleep[1],"time",-1*($iMicroSeconds*10)) Return $aSleep EndFunc Func _HighPrecisionSleep_Set(ByRef $aSleep, $iMicroSeconds) DllStructSetData($aSleep[1],"time",-1*($iMicroSeconds*10)) EndFunc Func _HighPrecisionSleep_UnInit(ByRef $aSleep) DllClose($aSleep[0]) Dim $aSleep[3] = [0,0,0] EndFunc $Sleep = _HighPrecisionSleep_Init(10) _HighPrecisionSleep($Sleep) ; sleep 10 microseconds _HighPrecisionSleep_Set($Sleep,100) _HighPrecisionSleep($Sleep) ; sleep 100 microseconds I have this in my script $Delay_value = GUICtrlRead($Delay) If WinExists("Notepad") Then WinActivate("Notepad") Sleep($Delay_value) Else MsgBox(0, "Wrong Window", "Open Up Nitto n00b") EndIf instead of the word sleep i want to refer it to the accurate sleep func and wait the time according to whats in the box based on 1000 = 1 sec. I use the Input method so that i can change how long it sleeps per computer i use this on in my gui. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 18, 2011 Developers Share Posted December 18, 2011 Could you define what is not accurate enough with Sleep() and what kind of accuracy you are looking for? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
SMOKE1990 Posted December 18, 2011 Author Share Posted December 18, 2011 nothing really is wrong with it I am completely done with my save exe and am exploring what autoit has to offer. I like how easy it is to code and run and stuff. I was just confused how to run it would it look like this $Delay_value = _HighPrecisionSleep_Init then in the script write this _HighPrecisionSleep($Delay_value) Link to comment Share on other sites More sharing options...
JohnOne Posted December 18, 2011 Share Posted December 18, 2011 What did the author of the function say? Or what were the examples in the thread you found this? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
KaFu Posted December 18, 2011 Share Posted December 18, 2011 Give this one a try... $h_DLL_NtDll = DllOpen("ntdll.dll") $Delay_value = GUICtrlRead($Delay) If WinExists("Notepad") Then WinActivate("Notepad") _HPSleep($Delay_value) Else MsgBox(0, "Wrong Window", "Open Up Nitto n00b") EndIf Func _HPSleep($fMs = 1) ; http://www.autoitscript.com/forum/topic/77905-sleep-down-to-100-nano-seconds/page__view__findpost__p__862689 ; default is milliseconds, otherwise microseconds (1 ms = 1000 µs) DllCall($h_DLL_NtDll, "dword", "NtDelayExecution", "int", 0, "int64*", -10000 * $fMs) ; ~ 1ms EndFunc ;==>_HPSleep 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...
SMOKE1990 Posted December 18, 2011 Author Share Posted December 18, 2011 almost completely copied and pasted and got this error Link to comment Share on other sites More sharing options...
JohnOne Posted December 18, 2011 Share Posted December 18, 2011 $fMs is an optional parameter in the function. _HPSleep($fMs = 1) When you say almost copied and pasted, was the almost, removing that parameter? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
SMOKE1990 Posted December 18, 2011 Author Share Posted December 18, 2011 no i copied this function in Func _HPSleep($fMs = 1) DllCall($h_DLL_NtDll, "dword", "NtDelayExecution", "int", 0, "int64*", -10000 * $fMs) ; ~ 1ms EndFunc but put it at the bottom of my script then the other part at the top $Launch_value = GUICtrlRead($Delay) $h_DLL_NtDll = DllOpen("ntdll.dll") If GUICtrlRead($Continue) = $GUI_CHECKED Then _HPSleep($Launch_value) movemouse(1, 100) ; just to make sure the sleep worked and the mouse moves to let me know EndIf Link to comment Share on other sites More sharing options...
JohnOne Posted December 18, 2011 Share Posted December 18, 2011 Well that's one of the oddest things I've seen lately. I certainly cannot explain it, sorry. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 18, 2011 Developers Share Posted December 18, 2011 Show the script that is giving the error. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Mat Posted December 18, 2011 Share Posted December 18, 2011 Is $h_DLL_NtDll declared as being global? AutoIt Project Listing Link to comment Share on other sites More sharing options...
SMOKE1990 Posted December 18, 2011 Author Share Posted December 18, 2011 haha thanks man ill keep on trying to see what is up. maybe delete the variable Link to comment Share on other sites More sharing options...
SMOKE1990 Posted December 18, 2011 Author Share Posted December 18, 2011 no should i set it as global? Link to comment Share on other sites More sharing options...
KaFu Posted December 18, 2011 Share Posted December 18, 2011 Yes, put the line Global $h_DLL_NtDll = DllOpen("ntdll.dll") somewhere at the top of your script outside of any function and before the first call to _HPSleep() to open the dll. I've done this to speed up the dllcall() function calls. The dll is automatically closed on program exit. 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...
SMOKE1990 Posted December 19, 2011 Author Share Posted December 19, 2011 Yea i did that and it worked, thank you so much both of you. The sleep is very accurate not as much as i need but way better than just the regular sleep. Link to comment Share on other sites More sharing options...
JohnOne Posted December 19, 2011 Share Posted December 19, 2011 Could you define what is not accurate enough with Sleep() and what kind of accuracy you are looking for?Josnothing really is wrong with it I am completely done with my save exe and am exploring what autoit has to offer. I like how easy it is to code and run and stuff. I was just confused how to run it would it look like this$Delay_value = _HighPrecisionSleep_Initthen in the script write this_HighPrecisionSleep($Delay_value)Yea i did that and it worked, thank you so much both of you. The sleep is very accurate not as much as i need but way better than just the regular sleep.Okay, so you changed your mind about what you need, nothing wrong with that.So what is it you need this sleep for? perhaps someone can better help you with this info. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kylomas Posted December 19, 2011 Share Posted December 19, 2011 smoke1990, As a curiousity, can you answer this question?Could you define what is not accurate enough with Sleep() and what kind of accuracy you are looking for?Jos kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jaberwacky Posted December 19, 2011 Share Posted December 19, 2011 (edited) nothing really is wrong with it I am completely done with my save exe and am exploring what autoit has to offer. I like how easy it is to code and run and stuff. I was just confused how to run it would it look like thisAside from that, I am curious about something. I've read that sleep functions cannot return an accurate value for durations less than 15ms. Is this true for all sleep functions. Is it true for AutoIt's Sleep? Edited December 19, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
MvGulik Posted December 19, 2011 Share Posted December 19, 2011 (edited) Don't know about others. But for AutoIt's Sleep() function. YepTimings General Sleep() times might be System depending ... Ergo:#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> _SleepRun() Func _SleepRun() Local Const $iMaxSleepTestValue = 64 Local Const $iTimingLoopCount = 4 Local $aResults_Min[$iMaxSleepTestValue + 1] Local $iTimer = 0, $iMin = 0 For $iSleep = 0 To $iMaxSleepTestValue $aResults_Min[$iSleep] = Floor(2 ^ 30) Next For $iSleep = 0 To $iMaxSleepTestValue ConsoleWrite('Loop: ' & $iSleep & '/' & $iMaxSleepTestValue & @CRLF) $iMin = $aResults_Min[$iSleep] For $i2 = 1 To $iTimingLoopCount $iTimer = TimerInit() Sleep($iSleep) $iTimer = TimerDiff($iTimer) If $iMin > $iTimer Then $iMin = $iTimer Next $aResults_Min[$iSleep] = Round($iMin) Next _ArrayDisplay($aResults_Min) EndFunc[Edit1: Always seem to forget to include the #include lines ... ][Edit2: ... something ... ] Edited December 19, 2011 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
jaberwacky Posted December 19, 2011 Share Posted December 19, 2011 Or was I thinking about timer? Hmm, I dunno! Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? 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