Window menu Alt+hotkey

Just starting out? Need help? Post your questions and find answers here.
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Window menu Alt+hotkey

Post by debashisde »

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
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Window menu Alt+hotkey

Post by charvista »

Debashisde,
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)
Hope this helps you.
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%
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Window menu Alt+hotkey

Post by charvista »

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%
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

Thanks for your reply.

But I want to display the "File" menu on pressing Alt-F

Here is my file menu:

Code: Select all

MenuTitle("&File")
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

Image
Last edited by debashisde on Wed Nov 10, 2010 12:30 pm, edited 1 time in total.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Window menu Alt+hotkey

Post by Trond »

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.
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

How does it work. Can you please share some code?

Does it work automatically? Or I have to add some short cuts. Please help.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Window menu Alt+hotkey

Post by Trond »

For menus it works automatically. I don't know about the buttons.
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

Does it work on Windows or it has the bug in Windows version as well?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Window menu Alt+hotkey

Post by Trond »

debashisde wrote:Does it work on Windows or it has the bug in Windows version as well?
In the 64-bit linux version and the 32-bit windows version it works correctly.
I haven't tested the 64-bit windows version, but I think it works.
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

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.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Window menu Alt+hotkey

Post by Shardik »

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.
It seems to be just the other way round! (tested always with PB 4.51)

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
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

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.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Window menu Alt+hotkey

Post by Shardik »

debashisde wrote:Pressing F10 shows the file menu!
That's also true for all my 3 tested Linux machines. In Windows XP SP3 the F10 key
highlights the File menu entry but doesn't drop down the menu entries.
Shardik wrote:In fact the underline character can be switched on and off by pressing the Alt key.
If somebody wants the underlined character in Windows to be displayed permanantly
(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.
debashisde
User
User
Posts: 11
Joined: Wed Oct 27, 2010 5:33 am

Re: Window menu Alt+hotkey

Post by debashisde »

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:

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 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.

Image
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Window menu Alt+hotkey

Post by skywalk »

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.
Post Reply