How to open the context menu of the window's title bar

Get help with using AutoHotkey and its commands and hotkeys
vladi
Posts: 4
Joined: 17 Aug 2017, 19:33

How to open the context menu of the window's title bar

17 Aug 2017, 20:20

How can I open the context menu of the window's title bar via AutoHotkey and then click a menu item by name?

Many thanks for any pointers!
User avatar
Exaskryz
Posts: 2435
Joined: 17 Oct 2015, 20:28

Re: How to open the context menu of the window's title bar

17 Aug 2017, 20:31

There is WinMenuSelectItem, but if you emulate human input you would use Send {Alt} to open the menu and then Send _ where _ is whatever the underlined character is in the menu. If that underlined character is to another menu, then you can send the next letter in that submenu.
User avatar
jeeswg
Posts: 2230
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to open the context menu of the window's title bar

17 Aug 2017, 20:33

You can invoke it by pressing alt+space.

Usually the commands are: Restore/Move/Size/Minimize/Maximize/Close, which all have AutoHotkey commands that you can use instead.

Does your menu have additional items like in Internet Explorer?

So you could send alt+space, down multiple times, enter. Or for example, 'alt+space, x' to maximise a window, i.e. you can use letters for items with accelerator keys.

Code: [Select all] [Download] GeSHi © Codebox Plus

q::
SendInput, !{Space}{Down 4} ;to focus the item
;SendInput, !{Space}{Down 4}{Enter} ;to invoke the item
return


It may also be possible to invoke an alt+space menu item directly using PostMessage and WM_COMMAND, so it might help if you mention what the program is. Cheers.

[EDIT:] @Exaskryz: does WinMenuSelectItem work on the alt+space menu?
User avatar
Exaskryz
Posts: 2435
Joined: 17 Oct 2015, 20:28

Re: How to open the context menu of the window's title bar

17 Aug 2017, 20:52

I don't believe WinMenuSelectItem works on that menu. It doesn't even appear to work on hidden menus it seems, at least those that hide the menu bar and require you to press Alt to show it (like in Firefox (fork)).
vladi
Posts: 4
Joined: 17 Aug 2017, 19:33

Re: How to open the context menu of the window's title bar

17 Aug 2017, 21:39

Problem is that the window contains a remote Windows session on another machine and Alt-Space is captured inside the window.
User avatar
jeeswg
Posts: 2230
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to open the context menu of the window's title bar

17 Aug 2017, 22:01

alt+left+down?

Sorry I'm not too familiar with remote sessions. Would PostMessage work?

Could you or anyone else give me a summary of (or link re.) some of the problems involved with AutoHotkey and remote sessions?
vladi
Posts: 4
Joined: 17 Aug 2017, 19:33

Re: How to open the context menu of the window's title bar

17 Aug 2017, 22:22

No, Alt-Left-Down gets captured inside the session as well.

I guess I really need to right-click the title bar of the window... Is there an easy way to do this with a given window?
User avatar
jeeswg
Posts: 2230
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to open the context menu of the window's title bar

17 Aug 2017, 22:35

Something like this?

Code: [Select all] [Download] GeSHi © Codebox Plus

q::
CoordMode, Mouse, Window
MouseMove, 100, 10
Send, {Click right}
return

Clicking works but keypresses don't?

You want to apply something to the main window, rather than the remote session? ... So you want to do things but without using the keyboard?

And so AHK is running on your PC rather than within the remote session?
Last edited by jeeswg on 17 Aug 2017, 22:50, edited 2 times in total.
User avatar
Exaskryz
Posts: 2435
Joined: 17 Oct 2015, 20:28

Re: How to open the context menu of the window's title bar

17 Aug 2017, 22:48

Is AHK running inside your remote session or on your "parent" or "encapsulated" desktop? You should be able to make AHK do anything you want on the desktop it is running on, though I have little experience with AHK and remote desktops. You can do things like ControlClick which targets a given window, and you can pass a coordinate or a control to it to right click. Just define the target window as the name of your desktop-sharing/viewing program.
vladi
Posts: 4
Joined: 17 Aug 2017, 19:33

Re: How to open the context menu of the window's title bar

17 Aug 2017, 22:50

Cool! That's it, jeeswg! Thanks a lot!

To your question whether keypresses not work: Well, they work, but are interpreted as keypresses for the remote window inside the session window. HTH.

My complete code now looks like this:

Code: [Select all] [Download] GeSHi © Codebox Plus

WinActivate, Remote Session
CoordMode, Mouse, Window
MouseMove, 100, 20
Send, {Click right}
Send, {Down}{Down}{Down}{Down}{Down}{Down}{Enter}
return


It's pretty hacky, but it does the job! :-)
User avatar
jeeswg
Posts: 2230
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to open the context menu of the window's title bar

17 Aug 2017, 22:53

See that confuses me though, because wouldn't those downs be sent to the remote window. Or perhaps that changes when the menu gets the focus.

Acc and accDoDefaultAction can be useful for invoking menu items.
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

[EDIT:] Btw you may be able to press a letter to invoke a menu item (hold alt to see underlines), and you could do {Down 6}.

[EDIT:] Examples of some alt+space menu/regular menu items in Internet Explorer being invoked via PostMessage:

Code: [Select all] [Download] GeSHi © Codebox Plus

PostMessage, 0x111, 41511,, TabWindowClass1, A ;WM_COMMAND := 0x111 ;Menu bar
PostMessage, 0x111, 41474,, TabWindowClass1, A ;WM_COMMAND := 0x111 ;Status bar
PostMessage, 0x111, 41484,, TabWindowClass1, A ;WM_COMMAND := 0x111 ;Lock the toolbars
PostMessage, 0x80F0, 42455,,, A ;WM_APP+240 := 0x80F0 ;Show tabs on a separate row
PostMessage, 0x111, 3460,, TabWindowClass1, A ;WM_COMMAND := 0x111 ;Caret browsing

Obtained via HotkeyP, mentioned here:
best utilities + best AutoHotkey scripts (+ useful tips) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=28149

[EDIT:] Internet Explorer is a bit unusual, normally you can invoke sysmenu items by doing this:
PostMessage, 0x112, % vID,,, A ;WM_SYSCOMMAND := 0x112
And normal menu items by doing this:
PostMessage, 0x111, % vID,,, A ;WM_COMMAND := 0x111

This can be useful for getting WM_COMMAND/WM_SYSCOMMAND IDs from menus:
Get Info from Context Menu (x64/x32 compatible) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31971

[EDIT:] A way to show the sysmenu without sending clicks, and how to invoke standard sysmenu items:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Return to “Ask For Help”

Who is online

Users browsing this forum: Helgef and 33 guests