Page 1 of 1
Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 06:00
by malcev
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
If I run this code, press f1, and press "up" or "down" key - nothing happens.
But if I close this menu and press once again f1 - "up" and "down" keys work.
Or I can run this script, then reload it, then press "f1" - "up" and "down" keys work.
Why "up" and "down" keys do not work at first time?
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 06:54
by Flarebrass
You might need to activate the GUI first.
Code: Select all
Menu, MyMenu, Add, Desktop, 1
Menu, MyMenu, Add, Programs, 2
F1::
Menu, MyMenu, Show
Gui +LastFound
WinActivate
return
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 07:14
by malcev
No. It does not work.
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 07:56
by Flarebrass
Oh duh, that's not a GUI so my suggestion is wrong. I've confirmed that your intended behavior works with other files, but not AHK scripts, so there's some command missing but I don't know what it is.
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 08:02
by Exaskryz
I cannot confirm this behavior. It worked properly for me when I put it into my test script. My auto-execute section, in case it makes any difference, is this:
Code: Select all
#If
SetWorkingDir, %A_ScriptDir%
#SingleInstance, Force
SetTitleMatchMode, 2
SetKeyDelay, 70
SetWinDelay, -1
CoordMode, ToolTip
CoordMode, Mouse, Screen
I am running AHK 32-bit Unicode v1.1.23.01 on Windows 8.1.
A suggestion for you may be doing this:
Code: Select all
F1::
Menu, MyMenu, Show
Menu, MyMenu, Hide
Menu, MyMenu, Show
return
However, if there is a perceptible flicker everytime you do this, you might work around it with a variable:
Code: Select all
F1::
If !recurrent
{
Menu, MyMenu, Show
Menu, MyMenu, Hide
recurrent:=true
}
Menu, MyMenu, Show
return
So only one Show is executed on the subsequent F1 presses.
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 08:52
by malcev
I am running AHK 32-bit Unicode v1.1.23.03 on Win7.
I can not find this command:
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 09:23
by kczx3
It worked fine for me as-is, first time. Windows 7 64-bit, AHK 1.1.23.05 Unicode 64-bit
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 09:45
by Shadowpheonix
I have found that there are times the pop-up menu does not automatically get focus when it is opened. I work around this by doing something like the following...
Code: Select all
Menu, MyMenu, Add, Item1, MenuHandler
Menu, MyMenu, Add, Item2, MenuHandler
SetTimer, ActivateMe, -25
Menu, MyMenu, Show
Return
MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return
ActivateMe:
WinActivate, %A_ScriptName%
Return
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 10:05
by Exaskryz
Ooops, there is no Hide command apparently. And Shadow reminded me that Menu will freeze a thread until something is selected (I think). My idea would only messily work with a second script. Shadow, does your idea work? My understanding is that the Timer won't fire until the menu has been dismissed.
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 10:25
by Shadowpheonix
The code I posted works for me using AHK 1.1.23.05 Unicode 64-bit on Windows 7. I have no idea why it works, because the Menu, MyMenu, Show does freeze the thread (which can be confirmed by putting additional commands into the timer).
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 11:57
by malcev
Arrow keys do not work for me with this code:
Code: Select all
Menu, MyMenu, Add, Item1, MenuHandler
Menu, MyMenu, Add, Item2, MenuHandler
SetTimer, ActivateMe, -25
Menu, MyMenu, Show
Return
MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return
ActivateMe:
WinActivate, %A_ScriptName%
Return
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 12:50
by malcev
But this code works.
I think this is bug.
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
Re: Arrow keys do not work in context menu at first time
Posted: 22 Apr 2016, 21:10
by malcev
Here I found some information:
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
I have written bug report:
https://autohotkey.com/boards/viewtopic ... 14&t=16809