Page 1 of 1

Using the Menu key in a script

Posted: 10 Jul 2014, 12:39
by AHKxx
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.

Re: Using the Menu key in a script

Posted: 10 Jul 2014, 14:16
by trismarck
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.

Re: Using the Menu key in a script

Posted: 10 Jul 2014, 14:26
by kon
Actually I think AHKxx may be referring to the AppsKey.

Re: Using the Menu key in a script

Posted: 10 Jul 2014, 17:19
by trismarck
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.

Re: Using the Menu key in a script

Posted: 10 Jul 2014, 19:24
by AHKxx
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!

Re: Using the Menu key in a script

Posted: 11 Jul 2014, 16:06
by trismarck
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).