Can I detect mouse over window title?

Get help with using AutoHotkey and its commands and hotkeys
andreasf
Posts: 13
Joined: 19 Aug 2016, 06:09

Can I detect mouse over window title?

28 Apr 2017, 13:28

I am trying to write a script to switch tabs in chrome using mouse wheel. Here's my idea:

If mouse over window title (chrome) then (
MouseWheelUp -> Ctrl+Shift+Tab
MouseWheelDown -> Ctrl+Tab
)

But I can't find a way to detect if the mouse is over the window title. Appreciate any help.
A_AhkUser
Posts: 1074
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: Can I detect mouse over window title?

28 Apr 2017, 15:11

See the documention, especially the #If [AHK_L] first example which defines a function taking advantage of MouseGetPos command in order achieve something similar to this.


Hope this helps.
User avatar
jeeswg
Posts: 6469
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Can I detect mouse over window title?

28 Apr 2017, 17:38

Try WM_NCHITTEST. Otherwise try AccViewer and look at the role text.

I'm not sure if Aero mode affects either of these, or if it does, if there are other methods.

[EDIT: WM_NCHITTEST appears not to be accurate in Aero mode, e.g. on Min/Max/Close buttons, identifies the wrong button near the borders. Tested on Windows 7.]
[EDIT: the Acc method appears to work even when Aero mode is on.]

WM_NCHITTEST example:

Code: Select all

q:: ;get information from object under cursor, WM_NCHITTEST
vList = ;continuation section
(
;HTERROR := -2
;HTTRANSPARENT := -1
;HTNOWHERE := 0
;HTCLIENT := 1
;HTCAPTION := 2
;HTSYSMENU := 3
;HTGROWBOX := 4 ;HTSIZE := 4
;HTMENU := 5
;HTHSCROLL := 6
;HTVSCROLL := 7
;HTMINBUTTON := 8 ;HTREDUCE := 8
;HTMAXBUTTON := 9 ;HTZOOM := 9
;HTLEFT := 10
;HTRIGHT := 11
;HTTOP := 12
;HTTOPLEFT := 13
;HTTOPRIGHT := 14
;HTBOTTOM := 15
;HTBOTTOMLEFT := 16
;HTBOTTOMRIGHT := 17
;HTBORDER := 18
; := 19
;HTCLOSE := 20
;HTHELP := 21
)

oArray := []
Loop, Parse, vList, `n
{
	oTemp := StrSplit(SubStr(A_LoopField, 2), " ")
	oArray[oTemp.3] := oTemp.1
}
oTemp := ""

CoordMode, Mouse, Screen
MouseGetPos, vPosX, vPosY, hWnd
SendMessage, 0x84, 0, vPosX|(vPosY<<16),, % "ahk_id " hWnd ;WM_NCHITTEST := 0x84
vNCHITTEST := ErrorLevel
MsgBox, % oArray[vNCHITTEST]
return
Last edited by jeeswg on 28 Apr 2017, 21:10, edited 4 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6469
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Can I detect mouse over window title?

28 Apr 2017, 18:15

Acc example:

Code: Select all

q:: ;get information from object under cursor, 'AccViewer Basic' (cf. AccViewer.ahk)
oAcc := Acc_ObjectFromPoint(vChildID)

;get role number
vRole := "", try vRole := oAcc.accRole(vChildID)
;get role text method 1
vRoleText1 := Acc_Role(oAcc, vChildID)
;get role text method 2 (using role number from earlier)
vRoleText2 := (vRole = "") ? "" : Acc_GetRoleText(vRole)
vName := "", try vName := oAcc.accName(vChildID)
vValue := "", try vValue := oAcc.accValue(vChildID)
oAcc := ""

vOutput := "role: " vRole "`r`n"
if (vRoleText1 == vRoleText2)
	vOutput .= "role text: " vRoleText1 "`r`n"
else
	vOutput .= "role text (1): " vRoleText1 "`r`n" "role text (2): " vRoleText2 "`r`n"
vOutput .= "name: " vName "`r`n"
vOutput .= "value: " vValue "`r`n"
;MsgBox, % vOutput
ToolTip, % vOutput
return
Btw the methods in this example, although they appear simple, caused me immense confusion in the past. It's nice to have it all sorted out for the first time. I'll put it in my Acc tutorial that I'm working on.

Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

[EDIT:] After trying some Acc hit tests on Google Chrome, you may be better off just checking whether the cursor is within the top n pixels of the window.

[EDIT:] If anyone has any further information on hit tests (retrieving information about what's under the cursor), I would be glad to know. Especially ways to accurately retrieve the same information that WM_NCHITTEST does, in Aero mode.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
andreasf
Posts: 13
Joined: 19 Aug 2016, 06:09

Re: Can I detect mouse over window title?

29 Apr 2017, 19:27

A_AhkUser wrote:See the documention, especially the #If [AHK_L] first example which defines a function taking advantage of MouseGetPos command in order achieve something similar to this.


Hope this helps.
Thank you for the response. The problem is that Chrome uses the same class for the address bar and the title. I would like a way detect window title only.
jeeswg wrote:Try WM_NCHITTEST. Otherwise try AccViewer and look at the role text.

I'm not sure if Aero mode affects either of these, or if it does, if there are other methods.

[EDIT: WM_NCHITTEST appears not to be accurate in Aero mode, e.g. on Min/Max/Close buttons, identifies the wrong button near the borders. Tested on Windows 7.]
[EDIT: the Acc method appears to work even when Aero mode is on.]

WM_NCHITTEST example:

Code: Select all

q:: ;get information from object under cursor, WM_NCHITTEST
vList = ;continuation section
(
;HTERROR := -2
;HTTRANSPARENT := -1
;HTNOWHERE := 0
;HTCLIENT := 1
;HTCAPTION := 2
;HTSYSMENU := 3
;HTGROWBOX := 4 ;HTSIZE := 4
;HTMENU := 5
;HTHSCROLL := 6
;HTVSCROLL := 7
;HTMINBUTTON := 8 ;HTREDUCE := 8
;HTMAXBUTTON := 9 ;HTZOOM := 9
;HTLEFT := 10
;HTRIGHT := 11
;HTTOP := 12
;HTTOPLEFT := 13
;HTTOPRIGHT := 14
;HTBOTTOM := 15
;HTBOTTOMLEFT := 16
;HTBOTTOMRIGHT := 17
;HTBORDER := 18
; := 19
;HTCLOSE := 20
;HTHELP := 21
)

oArray := []
Loop, Parse, vList, `n
{
	oTemp := StrSplit(SubStr(A_LoopField, 2), " ")
	oArray[oTemp.3] := oTemp.1
}
oTemp := ""

CoordMode, Mouse, Screen
MouseGetPos, vPosX, vPosY, hWnd
SendMessage, 0x84, 0, vPosX|(vPosY<<16),, % "ahk_id " hWnd ;WM_NCHITTEST := 0x84
vNCHITTEST := ErrorLevel
MsgBox, % oArray[vNCHITTEST]
return
jeeswg wrote:Acc example:

Code: Select all

q:: ;get information from object under cursor, 'AccViewer Basic' (cf. AccViewer.ahk)
oAcc := Acc_ObjectFromPoint(vChildID)

;get role number
vRole := "", try vRole := oAcc.accRole(vChildID)
;get role text method 1
vRoleText1 := Acc_Role(oAcc, vChildID)
;get role text method 2 (using role number from earlier)
vRoleText2 := (vRole = "") ? "" : Acc_GetRoleText(vRole)
vName := "", try vName := oAcc.accName(vChildID)
vValue := "", try vValue := oAcc.accValue(vChildID)
oAcc := ""

vOutput := "role: " vRole "`r`n"
if (vRoleText1 == vRoleText2)
	vOutput .= "role text: " vRoleText1 "`r`n"
else
	vOutput .= "role text (1): " vRoleText1 "`r`n" "role text (2): " vRoleText2 "`r`n"
vOutput .= "name: " vName "`r`n"
vOutput .= "value: " vValue "`r`n"
;MsgBox, % vOutput
ToolTip, % vOutput
return
Btw the methods in this example, although they appear simple, caused me immense confusion in the past. It's nice to have it all sorted out for the first time. I'll put it in my Acc tutorial that I'm working on.

Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

[EDIT:] After trying some Acc hit tests on Google Chrome, you may be better off just checking whether the cursor is within the top n pixels of the window.

[EDIT:] If anyone has any further information on hit tests (retrieving information about what's under the cursor), I would be glad to know. Especially ways to accurately retrieve the same information that WM_NCHITTEST does, in Aero mode.

First time I'm seeing these. I'll have a look, thanks!

I'm probably gonna use mouse pos.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], vsub and 209 guests