Why the results of these 2 commands may differ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
-_+
Posts: 70
Joined: 06 Dec 2014, 12:43

Why the results of these 2 commands may differ?

14 Dec 2015, 06:17

Code: Select all

MouseGetPos,,, id,, 1
vs

Code: Select all

MouseGetPos, x, y,,, 1
id := DllCall("WindowFromPoint", "Int", x, "Int", y)
These two codes sometimes generate different values. Why is that so?
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Why the results of these 2 commands may differ?

14 Dec 2015, 06:28

Can you in your tests further identify the class using WinGetClass, title, ahk_id %id%?

I'm going to guess that it has to do with CoordMode and how the x/y coordinates get stored and that the DllCall expects them to be Screen/Absolute positions.

In my testing, yes, if I use CoordMode, Mouse, Screen then they match up --- at least in a Mozilla browser. In Notepad++, the DllCall results in "Scintilla" while the MouseGetPos returns "Notepad++".
-_+
Posts: 70
Joined: 06 Dec 2014, 12:43

Re: Why the results of these 2 commands may differ?

14 Dec 2015, 07:05

In my script where I noticed this difference I use CoordMode, Mouse
The class was MozillaWindowClass, which is, unfortunately, is used in multiple sub-windows of a single Firefox window.
I'm going to guess that it has to do with CoordMode and how the x/y coordinates get stored and that the DllCall expects them to be Screen/Absolute positions.
The coordinates are relative to the screen (also, just FYI: I have a single screen).

Code: Select all

MouseGetPos, x, y, id, control, 1
Control is always blank for Firefox window.

Something is really weird here, because although I asked about this case as about two different pieces of code - they actually are two consecutive lines in the script and I noticed the difference in generated hwnd just because I got tired of some bug and so I started debugging all related variables' values.
The code is literally

Code: Select all

MouseGetPos, x, y, id, control, 1
id_from_target := DllCall("WindowFromPoint", "Int", x, "Int", y)
id is a hex value, while id_from_target is a decimal, but once I converted one of them - I realized that they match when I don't experience the bug and they differ when I do.
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Why the results of these 2 commands may differ?

14 Dec 2015, 08:25

MouseGetPos always retrieves the handle (ID/HWND) to the whole (top-level) window whereas WindowFromPoint() retrieves the handle to the control?window containing the mouse cursor, if any. Also, WindowFromPoint() has only one parameter, a POINT structure, so the DllCall will fail/retrieve wrong results with AHK U64.
-_+
Posts: 70
Joined: 06 Dec 2014, 12:43

Re: Why the results of these 2 commands may differ?

15 Dec 2015, 13:03

just_me, thank you.
But isn't what you've described WindorFromPoint() does - the same what ControlGetPos, x, y does?

Although I use U32, I wonder how to make WindowFromPoint() work with U64 (for just in case).
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Why the results of these 2 commands may differ?

15 Dec 2015, 16:51

Code: Select all

AHK         Windows
window      top-level (root) window
control     child window
WindowFromPoint() will get the handle to the child window containing the specified position, if any, so it will most likely retrieve the hwndControl retrieved by MouseGetPos, X, Y, hwndWin, hwndControl, 2 in this case.

Code: Select all

MouseGetPos, x, y, id, control, 1
Pos := ((Y & 0xFFFFFFFF) << 32) | (X & 0xFFFFFFFF)
id_from_target := DllCall("WindowFromPoint", "Int64", Pos, "UPtr")
-_+
Posts: 70
Joined: 06 Dec 2014, 12:43

Re: Why the results of these 2 commands may differ?

17 Dec 2015, 02:07

Thanks, just me, I will run some more tests.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Freddie, haomingchen1998, mmflume, scriptor2016, ShatterCoder and 85 guests