d3mon Posted May 12, 2008 Share Posted May 12, 2008 Hello everybody, same question like in the title : how can i know how long time a touch is pressed ? Is there a code for that ? Thanks for answers. No-life of autoit...what could be better ?LAST SCRIPTS WITH AUTO-IT : CLICK HERE Link to comment Share on other sites More sharing options...
monoceres Posted May 12, 2008 Share Posted May 12, 2008 Hello everybody,same question like in the title : how can i know how long time a touch is pressed ?Is there a code for that ?Thanks for answers.A touch? Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 12, 2008 Share Posted May 12, 2008 Hello everybody, same question like in the title : how can i know how long time a touch is pressed ? Is there a code for that ? Thanks for answers. It's not nice to encrypt your post and expect people to understand it... On the assumption you just want to know how long a key is pressed on the keyboard, try this: #include <Misc.au3> HotKeySet("{ESC}", "_Quit") Global $fPressed = False Global $hDLL = DllOpen("user32.dll") While 1 ; Monitor "X" key If _IsPressed("58", $hDLL) Then If $fPressed = False Then $iTimer = TimerInit() $fPressed = True EndIf TrayTip("X Monitor", "X has been pressed for: " & Round(TimerDiff($iTimer) / 1000, 3) & " seconds", 5) Else $fPressed = False EndIf Sleep(20) WEnd Func _Quit() DllClose($hDLL) Exit EndFunc Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
d3mon Posted May 13, 2008 Author Share Posted May 13, 2008 Thanks ! No-life of autoit...what could be better ?LAST SCRIPTS WITH AUTO-IT : CLICK HERE Link to comment Share on other sites More sharing options...
andybiochem Posted May 13, 2008 Share Posted May 13, 2008 Global $hDLL = DllOpen("user32.dll").I've been doing something similar to this, but without the dll.What does the extra DLL bit do? - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
TomZ Posted May 13, 2008 Share Posted May 13, 2008 (edited) It will speed up the script slightly, when calling the function alot of times. Edit; I wrote this up to proove the difference in speed: #include <Misc.au3> $n = 1000000;Number of tries $timer = TimerInit() For $x = 1 to $n _IsPressed("1B") Next $result1 = TimerDiff($timer) ConsoleWrite("Took " & Round($result1) & " miliseconds without DLLOpen; average of " & Round($result1 / $n, 4) & " miliseconds" & @CRLF) $dll = DllOpen("user32.dll") $timer = TimerInit() For $x = 1 to $n _IsPressed("1B", $dll) Next $result2 = TimerDiff($timer) ConsoleWrite("Took " & Round($result2) & " miliseconds with DLLOpen; average of " & Round($result2 / $n, 4) & " miliseconds" & @CRLF) DllClose($dll) ConsoleWrite(@CRLF & "Using DLLOpen is " & Round(($result1-$result2)/$result2*100) & "% faster." & @CRLF) Over one million _IsPressed calls, I got these results: Took 51768 miliseconds without DLLOpen; average of 0.0518 miliseconds Took 41171 miliseconds with DLLOpen; average of 0.0412 miliseconds Using DLLOpen is 26% faster. Edited May 13, 2008 by TomZ Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 13, 2008 Share Posted May 13, 2008 (edited) I've been doing something similar to this, but without the dll.What does the extra DLL bit do?As TomZ already pointed out: _IsPressed() is being called in a loop. By default, if the DLL handle is not provided, it will open the DLL, execute, then close the DLL for every time through the loop. If you open the DLL once and pass the handle to it, then _IsPressed() just executes without the open/close cycle for each loop. Over one million _IsPressed calls, I got these results:Took 51768 miliseconds without DLLOpen; average of 0.0518 milisecondsTook 41171 miliseconds with DLLOpen; average of 0.0412 milisecondsUsing DLLOpen is 26% faster.Nice test. In the indefinite loop I was using, total execution time was not critical, but there should be a reduction in the number of CPU cycles/Disk hits being sucked up by the script. So it has less impact on other things running at the same time. Edited May 13, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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