Jump to content

_IsPressed detecting to many


Recommended Posts

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

  • Moderators

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
EndFunc

I 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.

M23

Edit: Speeling!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by ReallySimple
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...