Arrow keys and shortcuts do not work in context menu at first time

Report problems with documented functionality
malcev
Posts: 709
Joined: 12 Aug 2014, 12:37

Arrow keys and shortcuts do not work in context menu at first time

24 Apr 2016, 07:42

If I run this code, press f1, and press "up" or "down" key - nothing happens.

Code: Select all

Menu, MyMenu, Add, Desktop, 1
Menu, MyMenu, Add, Programs, 2
Return
 
F1:: Menu, MyMenu, Show
 
1:
Run, %A_Desktop%
Return
 
2:
Run, %A_ProgramFiles%
Return
But this works all ok.

Code: Select all

DetectHiddenWindows, on
WinActivate, ahk_class AutoHotkey
Menu, MyMenu, Add, Desktop, 1
Menu, MyMenu, Add, Programs, 2
Return
 
F1:: Menu, MyMenu, Show
 
1:
Run, %A_Desktop%
Return
 
2:
Run, %A_ProgramFiles%
Return
I think this issue is because of:
Using shortkeys with TrackPopupMenu
If you are using shortkeys in your popup menu e.g. &About, E&xit then make sure SetForegroundWindow() is called before TrackPopupMenu().
Otherwise when the popup menu is activated pressing the shortkeys (A or x) will have no impact / not work.
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
malcev
Posts: 709
Joined: 12 Aug 2014, 12:37

Re: Arrow keys and shortcuts do not work in context menu at first time

24 Apr 2016, 12:11

1) If I create new script on desktop.
Run this script from desktop with double click and press f1 when desktop is active - then Up and Down do not work.

2) If I create new script on desktop.
Run this script from desktop with double click, activate firefox or skype window and press f1 - then Up and Down work.

2) If I reload.script, then Up and Down work at first time.
Win7 64 bit. Ahk unicode 32. bit 1.1.23.03.
lexikos
Posts: 7085
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Arrow keys and shortcuts do not work in context menu at first time

29 Apr 2016, 18:37

malcev wrote:I think this issue is because of:
It's not. If AutoHotkey didn't do that, keys would never work in menus unless you already had a script window active.

If SetForegroundWindow was failing, the active window would still be the Desktop. It is not. Running a separate script reporting the active window will show that the script is successfully activating itself, even when the keys aren't working. Note that focusing some other window will dismiss the menu; this would not happen if the script did not have focus.

It seems that AutoHotkey is doing all the right things and still getting the wrong result.

Menu-Show merely calls SetForegroundWindow. WinActivate is more aggressive - this shouldn't matter as activation is succeeding either way, but perhaps it does.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 1 guest