Saving Coords in Variable

5 posts in this topic

How would i go about saving a mouse position into a variable, atm i have this but im really not sure if its the proper way to do it

Im still very new to this


Global $xyLocation = MouseGetPos()

$Start_Exit_GUI = GUICreate("EXAMPLE", 228, 194, 398, 222) 

$Loc_Button = GUICtrlCreateButton("GET LOCATION", 0, 0, 227, 89, $WS_GROUP) 
GUICtrlSetFont(-1, 28, 400, 0, "Absolute Zero")

$Exit_Button = GUICtrlCreateButton("EXIT", 0, 96, 227, 97, $WS_GROUP)
GUICtrlSetFont(-1, 28, 400, 0, "Absolute Zero")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE

        Case $Loc_Botton 

        Case $Exit_Button 


Func LocButton()

    MsgBox(0, "NOTICE", "Click on the Location you want")

    MsgBox(0, "LOCATION","Location has been set")


Func Terminate()
    Exit 1



I want $xyLocation to hold whatever x-y Coordinates from where the user clicks AFTER the MsgBox() is gone


Thanks in advance for any help

Share this post

Link to post
Share on other sites

When first line execute your script store mouse coords in $xyLocation variable. I dont understand your question

Share this post

Link to post
Share on other sites


You do not have any of the includes you need to define your GUI variables.

This "Case $Loc_Botton" is a spelling error.

All of which you would have seen if you ran the script from SciTe using F5.

You already have a MouseGetPos, just move it to wherever you want it



Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post

Link to post
Share on other sites

#5 ·  Posted (edited)

I think I understand WHAT he wanted

And you need "track" Mouse Left Click instead of use a function that clicks on determined coord

Dont miss Opt MouseCoordMode in help file:

Sets the way coords are used in the mouse functions, either absolute coords or coords relative to the current active window:

0 = relative coords to the active window
1 = (default) absolute screen coordinates
2 = relative coords to the client area of the active window

#include <Misc.au3>


If are this you want then you need call MouseGetPos each time


Global $xyLocation


Func _GetMouseCoords()

MsgBox(0, "NOTICE", "Click on the Location you want")

; 01 = Left Click
While _IsPressed("01") = False



$xyLocation = MouseGetPos()

MsgBox(0, "LOCATION","Location has been set" & @CRLF & " X: " & $xyLocation[0] & " - Y: " & $xyLocation[1] & @CRLF)



Edited by GordonFreeman

Share this post

Link to post
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

  • Similar Content

    • autog
      By autog
      I left a comment in another thread on multitouch, but my question can be missed there and the solution might have no relationship with simulating multi-touch.
      So, is there any possibility to get the multiple x,y coordinates on a multi-touch device?
      Smth like mousegetpos, but multiple (?)
      Thank you for any idea / direction towards a solution.
    • DiveHigh
      By DiveHigh
      Hello There!  
      I've encountered a small issue i just cant seem to program my way out of...

      What im doing is:        ;or rather, what im trying to do is
      Pixelsearch for a color, within a part of my screen,
      If color is present, i will rightclick it, for a menu to appear,
      in which i want to Leftclick an option. Simplicity itself.   

      The issue is that because this menu appears in different parts of my screen, its complicated to select the option i want to click.
      There is no special color to it, and i cannot define the area in which to click, because the menu appears different places.
      The only thing that is in common for the menu is that the Leftclick needs to be (lets say) 30pixels below the rightclick

      What can be done,  but seemingly not by me, is to get the coordinates of the rightclick, and use them as the "starting point" from where the coordinates for the leftclick will be.
      (Not sure if that makes sence, but maybe the code below will help you understand)

      You guys like example codes, so therefore i will give it my best shot, and hope it proves usefull

      $pos = Pixelsearch(200, 400, 200, 400, 0xFFFFFF)        ;This color is what i need to rightclick to bring up the menu
      If not @Error then                                                               ;If the color is present
      (Mouseclick("Right", $pos[0], $pos[1], 1, 1)                   ;Rightclick it, to bring up menu
      ;Here comes the part i cannot get to work
      $x = MousegetPos(X)                                                          ;To get the Coordinate "X", so we can calculated with it for the position of the leftclick
      $y = MousegetPos(Y)                                                           ; To get the Coordinate "Y", so that can be calculated with for the position of the leftclick

      MouseClick("Left", $x[0], $y-30[1], 1, 1)                         ;This was supposed to give me a leftclick that is 30pixels below the rightclick.
      (The MouseGetPos(X), may seem as a waste of space in this example, but in my script i will need both. 
              Im only using one in the example, mainly so that i wont confuse myself, but also to make it easier to digest for you guys)

      I have not been able to find any topic that covers this, but my apologies if such a topic already exist in the forums. 

      Maybe while im at it, can i ask,   what good does the [0] and [1] do, when using a "$variable" as coordinate?   

      Thanks in advance
      - DiveHigh
    • johnmcloud
      By johnmcloud
      Hi guys, i have some problem with this script:

      #include <Misc.au3> Test() Func Test() Local $Position = MouseGetPos() While Not _IsPressed("1B") ; ESC button $Final = MouseGetPos() $LeftSX = @DesktopWidth/4 $Top = @DesktopHeight/4 TrayTip("", "Top: " & $Top & @CRLF & "Left:" & $LeftSX & @CRLF & "FinalPosition: " & $Final[0], "") If _IsPressed("01") Then If $Final[0] <= $LeftSX AND $Final[0] <= $Top Then MsgBox(0, 0, "Test") EndIf EndIf Sleep(100) WEnd Return Sleep(1000) EndFunc ;==>Test
      I want to set two areas ( one on left-down, one on right-top) and make an event on click. I don't know how to set the top position ( now work only for all left area ) and if i have to make the second area on Top-right in the same While-WEnd. I there is a way to improve it plase ask

      Thanks for advice