Jump to content

Get coords on click


Recommended Posts

Hello, I am trying to have my script wait until I left click and it sets a variable to those coords. So when I start the script, I have a button to start the function to pick the coords, I click the button and it just goes through my loop and sets the coords to the current location.

Local $x = 1, $pos

    While $x = 1
            if MouseClick("left") = 1 then
                $pos = MouseGetPos()
                $x = 0
            EndIf
    WEnd

Like it is now it will just drop through the loop and give me the coords of the mouse when I click the button.

I set the if to equal 0 to see what happens and it keeps clicking. So I think the if is just clicking when the loop runs and not waiting until I do the click.

Any ideas on what I can use to wait until I do the click?

Link to comment
Share on other sites

Here's one (of many different types) solution.. Have the button run a function like this..

#Include <Misc.au3> ; for _IsPressed()
Global $pos         ; this should be up where the other variables are declared

Func GetPos()
    While 1
        ToolTip("Click Somewhere Else now")
        Sleep(100)
        If _IsPressed("01") Then ExitLoop
    WEnd
    ToolTip("")
    $pos = MouseGetPos()
EndFunc
Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Here's one (of many different types) solution.. Have the button run a function like this..

#Include <Misc.au3> ; for _IsPressed()
Global $pos         ; this should be up where the other variables are declared

Func GetPos()
    While 1
        ToolTip("Click Somewhere Else now")
        Sleep(100)
        If _IsPressed("01") Then ExitLoop
    WEnd
    ToolTip("")
    $pos = MouseGetPos()
EndFunc

Well, this is certainly a possibility but it will unnecessarily block the script execution (and quitting) until the mouse button is clicked. Polling for user input in a loop is always the worse choice if you can catch a corresponding event and in this case you can. You can either use _WinAPI_SetCapture() / _WinAPI_ReleaseCapture() in combination with GUIGetMsg() = $GUI_EVENT_PRIMARYDOWN or _WinAPI_SetWindowsHookEx($WH_MOUSE) with a callback.

UDFS & Apps:

Spoiler

DDEML.au3 - DDE Client + Server
Localization.au3 - localize your scripts
TLI.au3 - type information on COM objects (TLBINF emulation)
TLBAutoEnum.au3 - auto-import of COM constants (enums)
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector - OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Link to comment
Share on other sites

You can either use _WinAPI_SetCapture() / _WinAPI_ReleaseCapture() in combination with GUIGetMsg() = $GUI_EVENT_PRIMARYDOWN or _WinAPI_SetWindowsHookEx($WH_MOUSE) with a callback

You grab the doohicky, and place it next to the thingamabob, and run it with the whatchamacallit. should work just fine.

Psst check the help file for what all that means. Just felt like smart A moment.

on a serious note.

I was actually looking to solve the same problem. Trying to get snowmakers example to work before i try other options.

thx

Link to comment
Share on other sites

You grab the doohicky, and place it next to the thingamabob, and run it with the whatchamacallit. should work just fine.

Psst check the help file for what all that means. Just felt like smart A moment.

Sorry, if you understood my post this way. I actually meant: cwoinfq38h02h92 n0911n13 9kmk sdf9023lkrnm234m c93. :(

I only wanted to point in direction where it should go. Not everybody always has time to write code for somebody else, ya know. And after all there's "Example Scripts" for ready to use scripts, this is exactly where you should look for keywords I've given (beside the AutoIt docs naturally).

Edited by doudou

UDFS & Apps:

Spoiler

DDEML.au3 - DDE Client + Server
Localization.au3 - localize your scripts
TLI.au3 - type information on COM objects (TLBINF emulation)
TLBAutoEnum.au3 - auto-import of COM constants (enums)
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector - OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Link to comment
Share on other sites

Sorry, if you understood my post this way. I actually meant: cwoinfq38h02h92 n0911n13 9kmk sdf9023lkrnm234m c93. :(

LOL

I only wanted to point in direction where it should go. Not everybody always has time to write code for somebody else, ya know. And after all there's "Example Scripts" for ready to use scripts, this is exactly where you should look for keywords I've given (beside the AutoIt docs naturally).

I am aware that the people on here do not want to spend all day and write scripts. And I am glad for that. Helps the rest of us to learn, And if you aren't willing to learn it then don't come here. That's how i look at it.

With that being said, can someone do this for me?? just kidding. I am actually still working with the example snowmaker had posted.

If i cant get that to work, i post what i have and then wait for the bouncing ideas.

And about my previous post. Simply meant to say that if you dont understand it now, you will.:)

Link to comment
Share on other sites

Well i wanted to function to wait for the user to do the click so it is up-to-date. My function works fine for getting the position of the mouse when it clicks and then it is set to the variable.

#Include <Misc.au3> ; Used for the _IsPressed
Global $pos ; To hold the position.

Func GetPos()
    Local $x = 1
    While $x = 1 ; Loop until the mouse is clicked.
            if _IsPressed("01") then ; If left mouse is pushed.
                $pos = MouseGetPos() ; Record the position.
                $x = 0 ; Change x to end loop.
            EndIf
    WEnd
EndFunc
Link to comment
Share on other sites

Well i wanted to function to wait for the user to do the click so it is up-to-date. My function works fine for getting the position of the mouse when it clicks and then it is set to the variable.

#Include <Misc.au3> ; Used for the _IsPressed
Global $pos ; To hold the position.

Func GetPos()
    Local $x = 1
    While $x = 1 ; Loop until the mouse is clicked.
            if _IsPressed("01") then ; If left mouse is pushed.
                $pos = MouseGetPos() ; Record the position.
                $x = 0 ; Change x to end loop.
            EndIf
    WEnd
EndFunc

At least extend your script to reduce processor load and to be able to react to ANYTHING but a click:

#Include <Misc.au3>
Global $pos
Global $hUserDll = DllOpen("user32.dll")

GetPos()

Func GetPos()
    While 1
        Local $msg = TrayGetMsg()
        If $msg Then
            ; do something meaningful
            ; ConsoleWrite("TrayGetMsg()=" & $msg & @LF)
        Else
            ToolTip("Click here")
            If _IsPressed("01", $hUserDll) Then ExitLoop
        EndIf
    WEnd
    ToolTip("")
    $pos = MouseGetPos()
EndFunc

UDFS & Apps:

Spoiler

DDEML.au3 - DDE Client + Server
Localization.au3 - localize your scripts
TLI.au3 - type information on COM objects (TLBINF emulation)
TLBAutoEnum.au3 - auto-import of COM constants (enums)
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector - OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

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