#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Global $x, $y
global $press
$press =0
Example()
Func Example()
Local $msg
HotKeySet("{Esc}", "GetPos")
GUICreate("Press Esc to Get Pos", 400, 400)
$x = GUICtrlCreateLabel("0", 10, 10, 50)
$y = GUICtrlCreateLabel("0", 10, 30, 50)
$xk = GUICtrlCreateLabel("0", 10, 40, 50)
$yk = GUICtrlCreateLabel("0", 10, 50, 50)
GUISetState()
; Run the GUI until the dialog is closed
Do
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_PRIMARYDOWN
GetPos()
if $press = 1 then $press = 0 else $press = 1
EndSwitch
Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>Example
Func GetPos()
Local $a
$a = GUIGetCursorInfo()
if $press = 1 Then
GUICtrlSetData($x, $a[0])
GUICtrlSetData($y, $a[1])
Else
GUICtrlSetData($xk, $a[0])
GUICtrlSetData($yk, $a[1])
EndIf
EndFunc