Wait for mouse click, save coordinates Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
09KR0058
Posts: 25
Joined: 11 Apr 2016, 18:08

Wait for mouse click, save coordinates

16 Jun 2017, 21:44

I have a script where I need the user to click somewhere on a window and get the mouse coordinates of where they clicked. Input won't work as it waits for a string to be entered.

Is there some way to do this? Don't really need a prompt, as it would be at the beginning when the script is first run by a hotkey. I would then wait for a click, save the coordinates, and go from there.

Thanks
GEV
Posts: 844
Joined: 25 Feb 2014, 00:50

Re: Wait for mouse click, save coordinates

17 Jun 2017, 01:24

Code: Select all

~LButton::
MouseGetPos, X, Y, WindowUnderMouse, ControlUnderMouse
; WinGetTitle, title, ahk_id %WindowUnderMouse%
; If (title = "Untitled - Notepad" and ControlUnderMouse = "Edit1" and X>100 and Y<200)
	; ToolTip, X = %X%`nY = %Y% ; do sth
return
or

Code: Select all

MouseGetPos, X, Y, A  ; A means the active window
is what you need in this case.
09KR0058
Posts: 25
Joined: 11 Apr 2016, 18:08

Re: Wait for mouse click, save coordinates

17 Jun 2017, 18:01

Thanks for the reply GEV, but that's not quite what I need. Also, I didn't explain myself very well.

Here's how the flow of the script should be:
Script is started via hotkey and waits for user to click somewhere on the screen
Use MouseGetPos and save the X & Y coordinates
Wait for user to click somewhere else on the screen
Use MouseGetPos and save the second X & Y coordinates
Continue executing the rest of the script

I just can't figure out how to get the script to wait for those two clicks.
Rohwedder
Posts: 3805
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Wait for mouse click, save coordinates  Topic is solved

18 Jun 2017, 02:48

Hallo,
try:

Code: Select all

i::
	ToolTip, click somewhere
	KeyWait, LButton, D
	MouseGetPos, X1, Y1
	KeyWait, LButton, U
	ToolTip,  click somewhere else
	KeyWait, LButton, D
	MouseGetPos, X2, Y2
	KeyWait, LButton, U
	ToolTip
	MsgBox, X1: %X1% Y1: %Y1% X2: %X2% Y2: %Y2%
Return
09KR0058
Posts: 25
Joined: 11 Apr 2016, 18:08

Re: Wait for mouse click, save coordinates

18 Jun 2017, 15:52

Perfect. Thank you so much. Guess I didn't dig deep enough. Had no idea that KeyWait could be used for mouse clicks.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, InGearX, jmone, Kellyzkorner_NJ, mikeyww, PuzzledGreatly, teadrinker, Xtra and 46 guests