Page 1 of 1

Select a line from a menu with the text...?

Posted: 27 Dec 2018, 05:26
by Elaphe666
How can I make my script select a specific line from a right-click menu (Chrome) based on the text on that line? Thank you.

Re: Select a line from a menu with the text...?

Posted: 27 Dec 2018, 09:15
by jeeswg
- Here are two variants. Both using old-school approaches, the second also using Acc.
- When I tested, accDoDefaultAction did not appear to work on the right-click menu, hence I had to use MouseClick.

Code: Select all

q:: ;chrome - get url under cursor
SendInput, {Click right}
Clipboard := ""
Sleep, 30
SendInput, e ;Copy link address
ClipWait, 3
MsgBox, % Clipboard
return

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

w:: ;chrome - get url under cursor
SendInput, {Click right}
WinWait, ahk_class Chrome_WidgetWin_2
hWnd := WinExist()
oAcc := Acc_Get("Object", "4.1.3.1", 0, "ahk_id " hWnd)
Clipboard := ""
;Sleep, 30
for _, oChild in Acc_Children(oAcc)
	if (oChild.accName(0) = "Copy link address")
	{
		oChild.accDoDefaultAction(0)
		oRect := Acc_Location(oChild)
		CoordMode, Mouse, Screen
		MouseGetPos, vCurX, vCurY
		MouseClick,, % oRect.x+oRect.w/2, % oRect.y+oRect.h/2
		MouseMove, % vCurX, % vCurY
	}
oAcc := oChild := ""
ClipWait, 3
MsgBox, % Clipboard
return