ken82m Posted October 7, 2008 Share Posted October 7, 2008 (edited) 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 October 10, 2008 by ken82m AndrewSchultz 1 "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 More sharing options...
ken82m Posted October 7, 2008 Author Share Posted October 7, 2008 (edited) 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 #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 October 7, 2008 by ken82m AndrewSchultz 1 "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 More sharing options...
Dr.Chi Posted April 3, 2009 Share Posted April 3, 2009 This did help me with a small bug I was having, thanks.. Link to comment Share on other sites More sharing options...
dreniarb Posted September 29, 2010 Share Posted September 29, 2010 This did help me with a small bug I was having, thanks..Helped me as well. Thanks. Link to comment Share on other sites More sharing options...
Frix Posted March 30, 2012 Share Posted March 30, 2012 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 More sharing options...
Moderators Melba23 Posted March 30, 2012 Moderators Share Posted March 30, 2012 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? M23 AnonymousX and AndrewSchultz 2 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...
Frix Posted March 30, 2012 Share Posted March 30, 2012 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 welcome. 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