TMainMenu: Hotkeys active with visible is false lazarus / 31-LCL ---------------------------------------------------------------------- Milsa · 2022-03-02 13:27 I have project of emulator. Project has TMainMenu and image of computer output. If image is fullscreen, main menu is visible. I need hide main menu. If I set MainMenu.Visible := False, then hotkeys in menu is inactive. Does exist an option to activate hotkeys in main menu with hidden / transparent main menu? I don't want to do duplicate keyboard shortcut handling. ---------------------------------------------------------------------- AlexTP · 2022-03-02 15:17 One have to check it in Delphi - does it disable hotkeys when menu Visible=false? ---------------------------------------------------------------------- Milsa · 2022-03-02 15:27 I do not know. I have Lazarus only. But I need menu hotkeys active when menu is invisible. ---------------------------------------------------------------------- Zvoni · 2022-03-02 15:39 Cannot confirm (FPC322-32Bit/Laz220-32Bit/Win10-64Bit) Though something weird: Invisible MenuItem with ShortCut, after pressing ShortCut, Lazarus jumps into Debug-Mode, and shows the Assembler-Window (as if on Breakpoint) Hit on F8, and OnClick-Event-Handler for invisible MenuItem gets processed ---------------------------------------------------------------------- Milsa · 2022-03-02 15:42 It's an older project. I need to find out what exactly is causing the problem there. I'm trying a clean project for verification. TMainMenu has not property Visible. ---------------------------------------------------------------------- Zvoni · 2022-03-02 15:45 Quote from: Milsa on March 02, 2022, 04:42:00 pmIt's an older project. I need to find out what exactly is causing the problem there. I'm trying a clean project for verification. TMainMenu has not property Visible. No, you have to add a TMenuItem (best with Menu-Editor). TMenuItem has Visible-Property TMainMenu is only the uppermost Container for the Menu-Tree ---------------------------------------------------------------------- Milsa · 2022-03-02 15:46 Please accept my apologies. My question should have been different: Why is there no Visible property in TMainMenu to quickly hide menus so that keyboard shortcuts work? I'm looking at the project right now and I have to remove the menu in a temporary variable there because I can't hide it. ---------------------------------------------------------------------- Milsa · 2022-03-02 15:47 Quote from: Zvoni on March 02, 2022, 04:45:56 pmQuote from: Milsa on March 02, 2022, 04:42:00 pmIt's an older project. I need to find out what exactly is causing the problem there. I'm trying a clean project for verification. TMainMenu has not property Visible. No, you have to add a TMenuItem (best with Menu-Editor). TMenuItem has Visible-Property Does exist option to hide all menu no every item? ---------------------------------------------------------------------- Zvoni · 2022-03-02 15:48 Quote from: Milsa on March 02, 2022, 04:46:25 pmPlease accept my apologies. My question should have been different: Why is there no Visible property in TMainMenu to quickly hide menus so that keyboard shortcuts work? I'm looking at the project right now and I have to remove the menu in a temporary variable there because I can't hide it. TMainMenu is a Non-Visual component and is just a Container. Everything you see in a MenuBar are TMenuItems ---------------------------------------------------------------------- Milsa · 2022-03-02 16:02 So, the only option is to hide all primary MenuItem? ---------------------------------------------------------------------- Milsa · 2022-03-02 16:08 Is this the simplest solution? Set the Tag to 1 for the root MenuItem and hide them in the loop? ---------------------------------------------------------------------- AlexTP · 2022-03-02 16:15 Try this hack: MainMenu1.Parent:= nil; //to hide the menubar ---------------------------------------------------------------------- balazsszekely · 2022-03-02 16:21 @Milsa You can achieve what are you after by creating different actions using a TActionList, then link each menu item to it's equivalent action. When you wish to hide the main menu, just do the following: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Form1.Menu := nil;The shortcut keys will still work via the ActionList. ---------------------------------------------------------------------- Milsa · 2022-03-02 16:22 Quote from: AlexTP on March 02, 2022, 05:15:03 pmTry this hack: MainMenu1.Parent:= nil; //to hide the menubar This is no good. Menu will be not work. ---------------------------------------------------------------------- Milsa · 2022-03-02 16:26 Quote from: Milsa on March 02, 2022, 05:22:44 pmQuote from: AlexTP on March 02, 2022, 05:15:03 pmTry this hack: MainMenu1.Parent:= nil; //to hide the menubar This is no good. Menu will be not work. That's a duplication of hotkeys, isn't it? I will try to hide MenuItems with Tag 1 (root element). ---------------------------------------------------------------------- jamie · 2022-03-02 22:46 You have some choices. Using the FORM's key handler and setting the KeyPreview := True allows you to view all key presses Then while in the OnKeyDown event of the form, you can inspect the Menu.Parent and if it's set to Nil, then it's assumed it is not visible. At this point you can loop through the menu items and subitems looking for the match shortcut. using "KeyToShortCut" gives you the value of the shortcut used in each menu. when you find the menu that has this shortcut then execute its OnClick handler if it is valid .  or you could just simply check all these values while in the forms event but then if you decide to change the shortcut key values in the menus you then would need to match them in the form's Onkeydown. This is why I suggest looping through the menu using only one list..  Its your party.