Jump to content

Read MouseGetPos?


Vzy
 Share

Recommended Posts

How does one read the X,Y MouseGetPos? and show it on a GUI?

I want to press a button, and it shows the coords in the input box so GUICtrlRead can read it.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Administrator\Downloads\koda_1.7.2.0\Forms\Tab.kxf
$TEST = GUICreate("TEST", 218, 444, 194, 125)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$label1 = GUICtrlCreateLabel("Coords 1", 52, 41, 113, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
$SX1 = GUICtrlCreateInput("0", 52, 73, 41, 21)
$SY1 = GUICtrlCreateInput("0", 124, 73, 41, 21)
$crosslabel1 = GUICtrlCreateLabel("X", 100, 73, 16, 24)
$Start = GUICtrlCreateButton("Start", 60, 401, 89, 33, $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("z","mousepos")


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

    EndSwitch
WEnd

; Functions

Func Start()
    

MouseMove(GuiCtrlRead($SX1),GuiCtrlRead($SY1))
SLeep(500)
    
EndFunc

Func mousepos()
    
$npos = MouseGetPos()
MsgBox(0, "Mouse x,y:", $npos[0] & "," & $npos[1])

EndFunc

Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc
Link to comment
Share on other sites

I had this script in my "old" directory, hope it helps. :mellow:

HotKeySet("{F7}", "_GetInfo")

Global $X_Input, $Y_Input, $Color_Input

; Main GUI
$GUI = GUICreate("Get Mouse Information", 220, 85)
GUICtrlCreateLabel("Press [F7] to get XY coordinates and color.", 10, 10)
GUICtrlCreateLabel("X:", 10 + 46, 35)
$X_Input = GUICtrlCreateInput("", 25 + 46, 30, 30)
GUICtrlCreateLabel("Y:", 65 + 46, 35)
$Y_Input = GUICtrlCreateInput("", 80 + 46, 30, 30)
GUICtrlCreateLabel("Hex color:", 10 + 45, 60)
$Color_Input = GUICtrlCreateInput("", 65 + 45, 55, 60)
GUISetState(@SW_SHOW, $GUI)

$WinPos = WinGetPos($GUI)

; Settings GUI
$GUI2 = GUICreate("Settings", 180, 100, $WinPos[0] + 240, $WinPos[1])
GUICtrlCreateLabel("Opt('MouseCoordMode', '", 10, 10, 145)
GUICtrlSetFont(-1, 10)
GUICtrlSetTip(-1, "Sets the way coords are used in the mouse functions, either absolute coords or coords relative to the current active window:" & _
                    @CRLF & "0 = relative coords to the active window" & _
                    @CRLF & "1 = absolute screen coordinates (default)" & _
                    @CRLF & "2 = relative coords to the client area of the active window")
$MCM = GUICtrlCreateInput("1", 150, 10, 15)
GUICtrlCreateLabel("')", 168, 10)
GUICtrlSetFont(-1, 10)
GUICtrlCreateLabel("Opt('PixelCoordMode', '", 10, 40, 145)
GUICtrlSetFont(-1, 10)
GUICtrlSetTip(-1, "Sets the way coords are used in the pixel functions, either absolute coords or coords relative to the window defined by hwnd (default active window):" & _
                    @CRLF & "0 = relative coords to the defined window" & _
                    @CRLF & "1 = absolute screen coordinates (default)" & _
                    @CRLF & "2 = relative coords to the client area of the defined window")
$PCM = GUICtrlCreateInput("1", 150, 40, 15)
GUICtrlCreateLabel("')", 168, 40)
GUICtrlSetFont(-1, 10)
$Set = GUICtrlCreateButton("Set", 40, 70, 100)

GUISetState(@SW_SHOW, $GUI2)
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $Set
        Opt('MouseCoordMode', GUICtrlRead($MCM))
        Opt('PixelCoordMode', GUICtrlRead($PCM))
    EndSwitch
WEnd

Func _GetInfo()
    $Pos = MouseGetPos()
    $Color = Hex(PixelGetColor($Pos[0], $Pos[1]), 6)
    
    GUICtrlSetData($X_Input, $Pos[0])
    GUICtrlSetData($Y_Input, $Pos[1])
    GUICtrlSetData($Color_Input, "0x" & $Color)
EndFunc

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Vzy this is not my script.This script was writed By M23 and i found it in my archive.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;SCRIPT WAS WRITED BY MELBA23
;autoitscript.com
; Create Global variables
Global $iMouse_Pos
Global $iMouse_Curr_Pos = 0
Global $iBegin = 0

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

; Create labels on GUI
$hLabel = GUICtrlCreateLabel("The Mouse X co-ordinate is: ", 10, 10, 150, 20)
$hCoord = GUICtrlCreateLabel("", 170, 20, 50, 20)
$hMoving = GUICtrlCreateLabel("", 10, 50, 200, 20)

GUISetState()

; Register the Windows message
GUIRegisterMsg($WM_MOUSEMOVE, "__MY_WM_MOUSEMOVE")

While 1

    ; Check for closure
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch

    ; Check if mouse has moved in x-direction
    If $iMouse_Pos <> $iMouse_Curr_Pos Then
    ; Set new position
    $iMouse_Curr_Pos = $iMouse_Pos
    ; Write coordinate
    GUICtrlSetData($hCoord, $iMouse_Pos)
    ; Reset the timer to keep moving
    $iBegin = TimerInit()
    ; Set Moving label
    GUICtrlSetData($hMoving, "Mouse is moving")
    EndIf

    ; Check if timer has run for more than 1/10 sec
    If TimerDiff($iBegin) > 100 Then
    ; Clear moving label
    If GUICtrlRead($hMoving) = "Mouse is moving" Then GUICtrlSetData($hMoving, "")
    EndIf

WEnd

Func __MY_WM_MOUSEMOVE($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
    Case $WM_MOUSEMOVE
    If IsHWnd($hGUI) Then $iMouse_Pos = MouseGetPos(0) & @CRLF & MouseGetPos(1) 

    EndSwitch
EndFunc ;==>__MY_WM_MOUSEMOVE
[size="5"] [/size]
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...