Right controlClick on ToolbarWindow321 autohotkey

1.8k views Asked by At

I'm quite new in autohotkey and I'm currently facing a misunderstanding about the ControlClick.

My aim is to right click on an icon on the toolbarWindow321 with a ControlClick to display the contextual menu. I do not want to use a Click or a Send as the action could be done when the session is locked on.

I search for a while in the web and tried several things.

ControlClick,,ahk_class Shell_TrayWnd,,R,NA x1500 y22

This thing works fine if I wanted to have the dropdown menu of the toolbar. That's not the case.

I tried something like this:

ControlClick,ToolbarWindow321,ahk_class Shell_TrayWnd,,Right,1,NA x1500 y22

But nothing is shown. I tried several coordinates, and used AutoIt3 spy to determined the position of my icon.

I'm certain I've done something wrong (of course or it would be working fine :)) Does somebody have an idea of what I must do to make it work?

2

There are 2 answers

0
vafylec On

I wrote some code to click on the Desktop button in Notepad's Save As window. On the Windows XP version of Notepad this was a ToolbarWindow32 control. The code uses functions from the Acc library, which you can put in your script's Lib folder.

Acc Library [AHK_L] (updated 09/27/2012) - Scripts and Functions - AutoHotkey Community https://autohotkey.com/board/topic/77303-acc-library-ahk-l-updated-09272012/

^q::
ControlGet, hCtl, Hwnd, , ToolbarWindow322, A
if !hCtl
Return

oAcc := Acc_Get("Object", "tool_bar", 0, "ahk_id " hCtl)
Loop, % oAcc.accChildCount
if (oAcc.accName(A_Index) = "Desktop")
if (1, oAcc.accDoDefaultAction(A_Index))
break
Return

EDIT: In your particular case, accDoDefaultAction might not correspond to right-click.

For reference, my script that works on both Windows XP and 7:

^q:: ;notepad (save as) - click Desktop button
^d:: ;notepad (save as) - click Desktop button
WinGet, hWnd, ID, A
hCtl := ""

if !hCtl ;check for treeview e.g. Win 7
{
ControlGet, hCtl, Hwnd, , SysTreeView321, ahk_id %hWnd%
if hCtl
oAcc := Acc_Get("Object", "outline", 0, "ahk_id " hCtl)
}

if !hCtl ;check for toolbar e.g. Win XP
{
ControlGet, hCtl, Hwnd, , ToolbarWindow322, ahk_id %hWnd%
if hCtl
oAcc := Acc_Get("Object", "tool_bar", 0, "ahk_id " hCtl)
}

Loop, % oAcc.accChildCount
if (oAcc.accName(A_Index) = "Desktop")
if (1, oAcc.accDoDefaultAction(A_Index))
break

Return
0
vafylec On

This issue may seem like a relatively trivial thing, a 'read the manual' question, but I remember having problems with it myself. Arguably the method at the bottom should work like the one above, but doesn't.

;notepad save as (windows xp version) left-click Desktop button)
ControlClick, ToolbarWindow322, A, , , , NA x40 y100

;taskbar (windows 7) right-click taskbar button
ControlClick, x260 y20, ahk_class Shell_TrayWnd, , R
ControlClick, x260 y20, ahk_class Shell_TrayWnd, , R, NA

;taskbar (windows 7) right-click taskbar button (DIDN'T WORK)
;(clicked the wrong part of the taskbar, at the far right I believe)
ControlClick, , ahk_class Shell_TrayWnd, , R, x260 y20
ControlClick, , ahk_class Shell_TrayWnd, , R, NA x260 y20

Notes on your code:

this is of the form that didn't work for me either:

ControlClick,,ahk_class Shell_TrayWnd,,R,NA x1500 y22

I believe this:

ControlClick,ToolbarWindow321,ahk_class Shell_TrayWnd,,Right,1,NA x1500 y22

should be this:

ControlClick,ToolbarWindow321,ahk_class Shell_TrayWnd,,Right,NA x1500 y22

with the '1' removed

Further note:

You may be able to use Acc to identify the coordinates of a button, and then use ControlClick to right-click it.