Using the Menu key in a script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Using the Menu key in a script

10 Jul 2014, 12:39

Hi. There's a simple macro I would like make but can't figure out how.

I want it to press and release the Windows menu key on the right (the one that brings up context menus) followed by {DOWN}{ENTER}.

And that's it. But I can't figure out how to properly specify that key, or even be certain how that key is referred to in AHK.

The script under a hot key and run on misspelled words to pop up the context menu, highlight the first item, and then execute. Most of the time that is the selection I'd want to make, and I'd like to make that key sequence as easy and fast as possible.

Anyone know how to reference that key?

Thanks.
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: Using the Menu key in a script

10 Jul 2014, 14:16

The name of the key is RWin.
Other commands:
To send keys, there is the Send command.
To wait for the window: WinWaitActive or WinWait.
To match the window, there is Active Window Info.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Using the Menu key in a script

10 Jul 2014, 14:26

Actually I think AHKxx may be referring to the AppsKey.
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: Using the Menu key in a script

10 Jul 2014, 17:19

Thanks. Thought that the 'menu' will just be the menu that appears after pressing Win, but that would be too simple. As a side-note for the author (if he doesn't already know it) is that the same effect can be obtained by pressing Shift+F10.
AHKxx
Posts: 75
Joined: 26 Feb 2014, 01:37

Re: Using the Menu key in a script

10 Jul 2014, 19:24

Thanks.

I didn't know that Shift+F10 = Menu key. That makes it much easier to deal with.

I've seen references to that key as RWin, and also with key code SC15D which would let you do things like:

RAlt & SC15D::MsgBox

But that was messy in all kinds of ways. Shift+F10 was the solution.

So I end up with this, which works to fix spelling on single words in Firefox and Scrivener, by opening the context menu and accepting the first item.

Code: Select all

!/::  
	SetKeyDelay, 200 ; can't be too low, 200 might be lowest, 
				    ; to accommodate lifting both hands from keys, 
				 ; otherwise it passes {ENTER}
	Send +{F10}
	Send {DOWN}     
	Sleep, 400     ; slow enough to see the menu, fast enough to not take too long
	Send {ENTER}
return  

Thanks!
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: Using the Menu key in a script

11 Jul 2014, 16:06

It is possible to speed up the script by explicitly waiting for the context menu window to exist (for which WinWait can be used). Here is a window class for the Firefox spelling window: ahk_class MozillaDropShadowWindowClass. Another improvement could be so that the hotkey only triggers when the Firefox window is the active window (#IfWinActive).
I'd also follow Kon's advise and use {AppsKey} to remove ambiguity.

Also, SC15D is a scan code 15D (vs a [virtual] key code).

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998 and 255 guests