Coordinate Check for ControlClick / Mouse Broadcasting?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cdenq
Posts: 4
Joined: 31 Jul 2021, 09:57

Coordinate Check for ControlClick / Mouse Broadcasting?

31 Jul 2021, 12:11

Hello!

My code below isn't producing the expected result, and my hunch is that it's an error with the coordinates possibly. Does anyone see an issue with the code?

Code: Select all

;-----------------------------------------------------------
; Mouse Broadcasting Hotkeys
;-----------------------------------------------------------
~XButton1::
	BroadcastMouse(A_ThisHotkey)
	Return

;-----------------------------------------------------------
; Mouse Broadcast Function
;-----------------------------------------------------------
BroadcastMouse(mouseKey)
{
	WinGetTitle, thisWindow
	MouseGetPos, xCoordinate, yCoordinate
	
	; This step is converting my raw hotkey input into a form that is recognizable by the ControlClick parameters
	If InStr(mouseKey, "~XButton1") {
		mouseKey = X1
	}
	
	ControlClick,,WinTitle,,%mouseKey%,, x%xCoordinate% y%yCoordinate%
	
	; Return my mouse and window focus to my orignal window (the window in which I first pressed XButton1)
	WinActivate, thisWindow
	MouseMove, xCoordinate, yCoordinate
}
Return
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Coordinate Check for ControlClick / Mouse Broadcasting?

31 Jul 2021, 12:22

Have you checked the value of thisWindow, to see what it is?

Is "WinTitle" the name of your window?
cdenq
Posts: 4
Joined: 31 Jul 2021, 09:57

Re: Coordinate Check for ControlClick / Mouse Broadcasting?

31 Jul 2021, 12:26

I just replaced the actual window title with "winTitle" for ease of reading.

When I run the code, my control clicks DO click into my inactive window, but it's not the same place (it's always in a seemingly random x y coordinate), which is why I thought it was an issue with my coordinate mode?

EDIT: did some additional testing. It's definitely an issue with controlclick coordinates.
My active window is bigger, my inactive window is a different size (but proportionate to the active window).
When I click in my active window, the coordinates are saved. Then, per the script, the controlclick goes through to my inactive window, but the coordinate is NOT the proporionate location as where I clicked in the main window, though I'm passing the same coordinates through (used a Msgbox to check before and after--the coordinates are the same). Repeating this process, the inactive window is getting clicked in the same place (so it's not a random spot), it's just not where I expect it be.
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Coordinate Check for ControlClick / Mouse Broadcasting?

31 Jul 2021, 12:57

The following appears to work. You could adjust accordingly.

Code: Select all

~LButton::broadcastMouse(A_ThisHotkey)

broadcastMouse(mouseKey) {
 Sleep, 25
 MouseGetPos, xpos, ypos
 ControlClick, Edit1, ahk_exe notepad.exe,, % RegExReplace(mouseKey, "(~|Button)"),, x%xpos% y%ypos%
 SoundBeep, 1500
}
Results may depend on the specific control in your target window.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, arcylix, drani, Nerafius, Rohwedder and 226 guests