Jump to content

Script to wait for Mouse click to get Mouse Coords [Resolved]


 Share

Recommended Posts

Is their anyway to get a script to wait for a mouse click anywhere on the screen?

I wrote a script that automates a function in a free app I use.

In the last few steps controlclick, controlwrite etc cause the app to crash.

So I had to resort to using mouse move/clicks.

It works perfectly for me but I'd like to contribute this to the community that developed the app.

Easy enough to do by storing the coords in an ini.

So I need to create a simple script to ask the user to click on 3 items and record the coords each time they click.

I know it's possible since au3record does it.

Basically I just need some code to wait for a "primary click", and then grab the mouse coords when it happens.

Thanks,

Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Think I figured it out, going to play with _IsPressed and see if that works.

Here's the code maybe it helps someone.

Why is it I always post stupid questions... lol :P

#Include <Misc.au3>
HotKeySet("{F3}", "Terminate")
$dll = DllOpen("user32.dll")

While 1
    Sleep ( 250 )
    If _IsPressed("01", $dll) Then
  $MousePos = MouseGetPos()
        MsgBox(0,"_IsPressed", "Mouse Button Pressed" & @CR & "X=" & $MousePos[0] & @CR & "Y=" & $MousePos[1])
        ExitLoop
    EndIf
WEnd

DllClose($dll)
Exit

Func Terminate()
    Exit 0
EndFunc
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...
  • 1 year later...

Hi,

I have exactly the same need as you (record mouse coords when user clicks somewhere) and tried the script you provided.

However, this did not work as expected for me:

If user clicks very fast, then the _IsPressed() function has not time to catch the button down state and the exitloop is not executed.

I obviously tried to reduce Sleep() time (even tried to remove Sleep()), this did not help very much. The best behavior I got is when there is no Sleep() at all but this makes CPU run at 100% load and very fast clicks still not are catched.

Something that would solve the problem is something just like the HotKeySet() function (which is event triggered) but this function seams working only with keyboard keys, not with mouse buttons.

Does anyone have an idea on how to deal with that ?

Thanks a lot by advance.

Link to comment
Share on other sites

  • Moderators

Frix,

You must have a very strange machine to miss clicks using that code - I need to use additional code to wait until the mousebutton is released to prevent multiple hits even when I try to make the fastest click I can manage:

#include <Misc.au3>

HotKeySet("{ESC}", "Terminate")

$dll = DllOpen("user32.dll")

While 1
    Sleep(10) ; This enough to prevent CPU overload <<<<<<<<<<<<<<<<<<<<<<<<
    If _IsPressed("01", $dll) Then
        $MousePos = MouseGetPos()
        ConsoleWrite("Mouse Button Pressed" & @CRLF & "X=" & $MousePos[0] & @CRLF & "Y=" & $MousePos[1] & @CRLF)
        While _IsPressed("01", $dll)
            Sleep(10)
        WEnd
    EndIf
WEnd

Func Terminate()
    DllClose($dll)
    Exit 0
EndFunc

Are you sure you are missing clicks - are they perhaps being eaten by the GUI on which you are clicking? :oops:

M23

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 answer Melba,

Actually I did the same code to prevent from double-click.

But yes, I definitely am missing clicks, they are not eaten by any GUI.

On slow clicks, no problem, the script reacts as expected but on fast clicks it simply ignores ~80% of them.

Maybe it is in relation with my OS ? I am running Win7 x64...

Anyway, thanks...

Any other solution (except slow clicking :oops: welcome.

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