trying to hide a menu by pressing the key that shows it

Get help with using AutoHotkey and its commands and hotkeys
Herchi
Posts: 21
Joined: 07 Mar 2018, 08:19

trying to hide a menu by pressing the key that shows it

01 Aug 2020, 14:25

I have this:

Code: Select all

; GLOBAL
GLOBAL showMenu := false

; Create the popup menu by adding some items to it.
Menu, MyMenu, Add, Item1, MenuHandler
Menu, MyMenu, Add, Item2, MenuHandler
Menu, MyMenu, Add  ; Add a separator line.

; Create another menu destined to become a submenu of the above menu.
Menu, Submenu1, Add, Item1, MenuHandler
Menu, Submenu1, Add, Item2, MenuHandler

; Create a submenu in the first menu (a right-arrow indicator). When the user selects it, the second menu is displayed.
Menu, MyMenu, Add, My Submenu, :Submenu1

Menu, MyMenu, Add  ; Add a separator line below the submenu.
Menu, MyMenu, Add, Item3, MenuHandler  ; Add another menu item beneath the submenu.
return  ; End of script's auto-execute section.

MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return

#z:: ; i.e. press the Win-Z hotkey to show the menu.
    if (%showMenu%) {
        showMenu = false
        Menu, MyMenu, Hide
    } else {
        showMenu = true
        Menu, MyMenu, Show
    }
Return
I want to show/hide menu with Win-Z (using showMenu).

Thank u.
Rohwedder
Posts: 3390
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: trying to hide a menu by pressing the key that shows it

02 Aug 2020, 02:47

Hallo,
try:

Code: Select all

; GLOBAL
GLOBAL showMenu := false

; Create the popup menu by adding some items to it.
Menu, MyMenu, Add, Item1, MenuHandler
Menu, MyMenu, Add, Item2, MenuHandler
Menu, MyMenu, Add  ; Add a separator line.

; Create another menu destined to become a submenu of the above menu.
Menu, Submenu1, Add, Item1, MenuHandler
Menu, Submenu1, Add, Item2, MenuHandler

; Create a submenu in the first menu (a right-arrow indicator). When the user selects it, the second menu is displayed.
Menu, MyMenu, Add, My Submenu, :Submenu1

Menu, MyMenu, Add  ; Add a separator line below the submenu.
Menu, MyMenu, Add, Item3, MenuHandler  ; Add another menu item beneath the submenu.
return  ; End of script's auto-execute section.

MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return

#z:: ; i.e. press the Win-Z hotkey to show the menu.
FileDelete, ~.ahk
FileAppend,
(
#NoTrayIcon
WinWaitClose, ahk_class #32768 ahk_exe Autohotkey.exe
ExitApp
%A_ThisHotkey%::WinClose, ahk_class #32768 ahk_exe Autohotkey.exe
), ~.ahk
Run, ~.ahk
Menu, MyMenu, Show
Return
Uses a temporary hidden second script.
Herchi
Posts: 21
Joined: 07 Mar 2018, 08:19

Re: trying to hide a menu by pressing the key that shows it

03 Aug 2020, 16:22

my code generates autohotkey.exe
your code: rohwedder.exe

If I try to use only rohwedder.exe
odd hotkey: windows ask me how I want to open the file and show me the menu.
even hotkey: same as the odd.

If I try autohotkey.exe and rohwedder.exe
first hotkey: show me the menu.
second hotkey: no hide the menu.
if I cancel the menu with 'Esc'
third hotkey:

Code: Select all

error parameter #2 invalid
specificaly: hide
Line#
--> 017: Menu, MyMenu, Hide
The current thread will exit
fourth hotkey: like the first

I film a gif with the test
https://i.imgur.com/Lx1pqLS.gif [Mod edit: Link fixed.]
Rohwedder
Posts: 3390
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: trying to hide a menu by pressing the key that shows it

04 Aug 2020, 01:45

You compile your scripts?!
I really only have one compiled script, a guard that acts when Autohotkey.exe stops running.
Then try:

Code: Select all

#z:: ; i.e. press the Win-Z hotkey to show the menu.
FileDelete, ~.ahk
FileAppend,
(
#NoTrayIcon
WinWaitClose, ahk_class #32768
ExitApp
%A_ThisHotkey%::
While, WinExist("ahk_class #32768")
	WinClose, ahk_class #32768
Return
), ~.ahk
Run, ~.ahk
Menu, MyMenu, Show
Return
But it can happen that wrong ahk_class #32768 windows are closed.
Herchi
Posts: 21
Joined: 07 Mar 2018, 08:19

Re: trying to hide a menu by pressing the key that shows it

05 Aug 2020, 13:49

Rohwedder wrote:
04 Aug 2020, 01:45
You compile your scripts?!
I really only have one compiled script, a guard that acts when Autohotkey.exe stops running.
Then try:

Code: Select all

#z:: ; i.e. press the Win-Z hotkey to show the menu.
FileDelete, ~.ahk
FileAppend,
(
#NoTrayIcon
WinWaitClose, ahk_class #32768
ExitApp
%A_ThisHotkey%::
While, WinExist("ahk_class #32768")
	WinClose, ahk_class #32768
Return
), ~.ahk
Run, ~.ahk
Menu, MyMenu, Show
Return
But it can happen that wrong ahk_class #32768 windows are closed.
I don't understand it, sure...

I compiled the 3 versions: my Autohotkey.exe (first), your rohwedder.exe and this last (guard.exe).
I tried to use
1) only guard.exe
2) guard.exe and Autohotkey.exe
3) guard.exe and rohwedder.exe

the result is not adequate. the safest thing is that I do not understand you with the steps to take. :( sorry

Return to “Ask For Help”

Who is online

Users browsing this forum: aurelius, Bill, GreatGreen, Sabestian Caine, swagfag and 45 guests