Window menu Alt+hotkey
-
- User
- Posts: 11
- Joined: Wed Oct 27, 2010 5:33 am
Window menu Alt+hotkey
Hello everyone,
I am new to PureBasic. I just downloaded a demo version for Linux and trying out some coding.
I can not make the Alt+key menu work for menus. For example:
File menu is shown when:
1) I click on the "File" menu or
2) press Alt-F
The AddMenuItem() takes & in the text to display _ in the character which signifies that pressing Alt+that key will activate it. But how do I make it work with AddKeyboardShortcut()?
I am not talking about the ShortcutKey like Ctrl+C for menu-item "Copy" etc. I am talking about the top level menus. For example, Pressing Alt-F-X normally activates the "File"->"Exit" menu.
Another question is that: How do I show the _ character (similar to menus using &) in ButtonGadget. If I specify the text with & character, the _ is not shown, instead the & character itself is shown. Though, in this case, I am able to add the shortcut key, but the _ character is not shown.
Thanks in advance for your help.
Regards,
Debashis
I am new to PureBasic. I just downloaded a demo version for Linux and trying out some coding.
I can not make the Alt+key menu work for menus. For example:
File menu is shown when:
1) I click on the "File" menu or
2) press Alt-F
The AddMenuItem() takes & in the text to display _ in the character which signifies that pressing Alt+that key will activate it. But how do I make it work with AddKeyboardShortcut()?
I am not talking about the ShortcutKey like Ctrl+C for menu-item "Copy" etc. I am talking about the top level menus. For example, Pressing Alt-F-X normally activates the "File"->"Exit" menu.
Another question is that: How do I show the _ character (similar to menus using &) in ButtonGadget. If I specify the text with & character, the _ is not shown, instead the & character itself is shown. Though, in this case, I am able to add the shortcut key, but the _ character is not shown.
Thanks in advance for your help.
Regards,
Debashis
Re: Window menu Alt+hotkey
Debashisde,
Welcome to PureBasic! No doubt you will love it.
Here is a fragment of how to program the Alt+X to exit.
Hope this helps you.
Welcome to PureBasic! No doubt you will love it.
Here is a fragment of how to program the Alt+X to exit.
Code: Select all
MenuTitle("File")
MenuItem(1, "Exit"+Chr(9)+"Alt+X") : AddKeyboardShortcut(Win, #PB_Shortcut_Alt | #PB_Shortcut_X, 1)
Last edited by charvista on Wed Oct 27, 2010 12:07 pm, edited 1 time in total.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: Window menu Alt+hotkey
Here is a working example.
Code: Select all
Win = OpenWindow(#PB_Any, 100, 100, 850, 600, "Test Menu",#PB_Window_SystemMenu)
Menu = CreateMenu(#PB_Any, WindowID(Win))
MenuTitle("File")
MenuItem( 1, "&Open"+Chr(9)+"Alt+O") : AddKeyboardShortcut(Win, #PB_Shortcut_Alt | #PB_Shortcut_O, 1)
MenuItem( 2, "E&xit"+Chr(9)+"Alt+X") : AddKeyboardShortcut(Win, #PB_Shortcut_Alt | #PB_Shortcut_X, 2)
Repeat
Event = WaitWindowEvent()
EvMen = EventMenu()
Select Event
Case #PB_Event_Menu
Select EvMen
Case 1
MessageRequester("Info", "Open was selected",0)
Case 2
Quit=1
Default
MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1 Or Event = #WM_CHAR
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
-
- User
- Posts: 11
- Joined: Wed Oct 27, 2010 5:33 am
Re: Window menu Alt+hotkey
Thanks for your reply.
But I want to display the "File" menu on pressing Alt-F
Here is my file menu:
Sine the File menu has "&F" which is displayed as F it should get activated on pressing Alt-F.
I am not being able to achieve that.
In Short, I want the following to be shown on pressing Alt-F

But I want to display the "File" menu on pressing Alt-F
Here is my file menu:
Code: Select all
MenuTitle("&File")
I am not being able to achieve that.
In Short, I want the following to be shown on pressing Alt-F

Last edited by debashisde on Wed Nov 10, 2010 12:30 pm, edited 1 time in total.
Re: Window menu Alt+hotkey
There is a bug in the 32-bit linux version regarding this menu functionality. In the 64-bit linux version and the 32-bit windows version it works correctly.
-
- User
- Posts: 11
- Joined: Wed Oct 27, 2010 5:33 am
Re: Window menu Alt+hotkey
How does it work. Can you please share some code?
Does it work automatically? Or I have to add some short cuts. Please help.
Does it work automatically? Or I have to add some short cuts. Please help.
Re: Window menu Alt+hotkey
For menus it works automatically. I don't know about the buttons.
-
- User
- Posts: 11
- Joined: Wed Oct 27, 2010 5:33 am
Re: Window menu Alt+hotkey
Does it work on Windows or it has the bug in Windows version as well?
Re: Window menu Alt+hotkey
debashisde wrote:Does it work on Windows or it has the bug in Windows version as well?
I haven't tested the 64-bit windows version, but I think it works.In the 64-bit linux version and the 32-bit windows version it works correctly.
-
- User
- Posts: 11
- Joined: Wed Oct 27, 2010 5:33 am
Re: Window menu Alt+hotkey
Is the Linux issue a known bug to the developers?
Let me try to find a Windows machine and check it there.
Thanks for your help.
Let me try to find a Windows machine and check it there.
Thanks for your help.
Re: Window menu Alt+hotkey
It seems to be just the other way round! (tested always with PB 4.51)Trond wrote:There is a bug in the 32-bit linux version regarding this menu functionality. In the 64-bit linux version and the 32-bit windows version it works correctly.
Linux:
Alt+F in my code example below works in 32 Bit Linux (andLinux/Kubuntu 9.04
running as a task in Windows XP SP3) and in 32 Bit OpenSuSE 11.2, but not in
64 Bit Linux (SLES 10 SP3 as virtual machine in VMware ESX 4.1).
Windows:
In Windows XP SP3 x86 and Windows 7 x86 Alt+F works, but the underline in
letter F is only displayed after the Alt key is pressed. In fact the underline
character can be switched on and off by pressing the Alt key. The 64 bit version
of Windows 7 I can't test at the moment.
Code: Select all
OpenWindow(0, 100, 100, 300, 100, "Test Menu")
CreateMenu(0, WindowID(0))
MenuTitle("&File")
MenuItem(0, "&Open" + #TAB$ + "Alt+O")
MenuItem(1, "E&xit" + #TAB$ + "Alt+X")
AddKeyboardShortcut(0, #PB_Shortcut_Alt | #PB_Shortcut_O, 0)
AddKeyboardShortcut(0, #PB_Shortcut_Alt | #PB_Shortcut_X, 1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
Case 0
Debug "'Open' was selected"
Case 1
Debug "'Exit' was selected"
Break
EndSelect
EndSelect
ForEver
-
- User
- Posts: 11
- Joined: Wed Oct 27, 2010 5:33 am
Re: Window menu Alt+hotkey
I am using 32 bit Fedora Core 6 and Alt-F does not work here. Pressing F10 shows the file menu!
I didn't check the Windows version though.
I didn't check the Windows version though.
Re: Window menu Alt+hotkey
That's also true for all my 3 tested Linux machines. In Windows XP SP3 the F10 keydebashisde wrote:Pressing F10 shows the file menu!
highlights the File menu entry but doesn't drop down the menu entries.
If somebody wants the underlined character in Windows to be displayed permanantlyShardik wrote:In fact the underline character can be switched on and off by pressing the Alt key.
(if XP Skins is enabled) he has to uncheck the option
Hide underlined letters for keyboard navigation until I press the Alt key
in Display Properties --> Appearance --> Effects.
-
- User
- Posts: 11
- Joined: Wed Oct 27, 2010 5:33 am
Re: Window menu Alt+hotkey
Hello, I confirm that the Windows version does work. I mean, pressing Alt-F shows the file menu.
But, now, I am having a strange problem with the following code:
In Linux, the button label is displayed as "&Add" (see the attached picture).
In Windows, when I run the program using "F5" it shows "Add", but when I start it by clicking the "Compile/Run" tool button the underline character is not shown, the label becomes plain "Add".
Is this also a bug or I am doing something wrong?
Note that the short-cut does work correctly, I mean pressing Alt-A activates the button.
Please help.

But, now, I am having a strange problem with the following code:
Code: Select all
#window_0 = 0
#button_0 = 1
#app_name = "Test"
OpenWindow(#window_0, #PB_Ignore, #PB_Ignore, 300, 200, #app_name, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#button_0, 100, 100, 100, 30, "&Add")
AddKeyboardShortcut(#window_0, #PB_Shortcut_Alt | #PB_Shortcut_A, #button_0)
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget, #PB_Event_Menu
Select (EventGadget())
Case #button_0
MessageRequester(#app_name, "button clicked")
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
In Windows, when I run the program using "F5" it shows "Add", but when I start it by clicking the "Compile/Run" tool button the underline character is not shown, the label becomes plain "Add".
Is this also a bug or I am doing something wrong?
Note that the short-cut does work correctly, I mean pressing Alt-A activates the button.
Please help.

Re: Window menu Alt+hotkey
I have never gotten a button(command button in VB6) to fire with the "&" something keystroke in any Windows version.
Only [Enter] or [Spacebar] when it has the focus.
Only [Enter] or [Spacebar] when it has the focus.