ReallySimple Posted October 8, 2009 Share Posted October 8, 2009 Hello, Just fooling around with autoit. Trying to create a simple 'mouse counter' to see how fast I can click the mouse. How ever all it does is log about 5 times more then it should, I think it's because _IsPressed keeps counting while the keys held down, so even holding it down a few milaseconds can greatly mess it up. I tried adding some sleeps, but thats a half-a** solution I found out. Is there any way to just detect it as pressed once? Here is what I'm trying: #include <Misc.au3> #Include <File.au3> While 1 Sleep ( 100 ) If _IsPressed("01") or _IsPressed("02") Then _FileWriteLog(@ScriptDir & "\log.txt","1 ball shot") EndIf WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 8, 2009 Moderators Share Posted October 8, 2009 (edited) ReallySimple,Your guess as to the cause of the problem is spot on! What you need is another loop to check if the mouse button is still down and wait until it is not. Look at this:#include <Misc.au3> #Include <File.au3> HotKeySet("{ESC}", "On_Exit") $dll = DllOpen("user32.dll") $iCount = 0 While 1 Sleep(10) If _IsPressed("01", $dll) Or _IsPressed("02", $dll) Then $iCount += 1 ConsoleWrite("Click " & $iCount & @CRLF) Do Sleep(10) Until Not(_IsPressed("01", $dll)) And Not(_IsPressed("02", $dll)) EndIf WEnd Func On_Exit() DllClose($dll) Exit EndFuncI have also added a couple of lines. If you are calling _IsPressed as often as you are, it is a good idea to open the DLL just the once - much qucker than opening it each time you call the function. I also added a hotkey so that you can close the DLL when you exit - AutoIt will do this for you automatically, but clearing up your own code is a good habit to get into!I hope this answers your question.M23Edit: Speeling! Edited October 8, 2009 by Melba23 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...
ReallySimple Posted October 8, 2009 Author Share Posted October 8, 2009 (edited) Thanks for that, worked like a charm. I played around with TimerDiff and TimerInt and got it to say how many clicks i made in how many seconds. How can I use auto it to get the averge of that? EG: I get the result I clicked 30 times in 8076 MS, how can I use auto it to grab the average? (EG Sorry for these beginner questions Edited October 8, 2009 by ReallySimple Link to comment Share on other sites More sharing options...
omikron48 Posted October 8, 2009 Share Posted October 8, 2009 30 * 1000 / 8076? This will give you clicks per second. Multiply by 60 to get clicks per minute. Link to comment Share on other sites More sharing options...
ReallySimple Posted October 8, 2009 Author Share Posted October 8, 2009 Ahh yeah I didn't know the simple math functions syntax built into autoit simple enough thanks 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