Page 1 of 2

Window menu Alt+hotkey

Posted: Wed Oct 27, 2010 5:59 am
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

Re: Window menu Alt+hotkey

Posted: Wed Oct 27, 2010 11:58 am
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.

Re: Window menu Alt+hotkey

Posted: Wed Oct 27, 2010 12:07 pm
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

Re: Window menu Alt+hotkey

Posted: Wed Oct 27, 2010 12:19 pm
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

Re: Window menu Alt+hotkey

Posted: Wed Oct 27, 2010 12:28 pm
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.

Re: Window menu Alt+hotkey

Posted: Wed Oct 27, 2010 12:31 pm
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.

Re: Window menu Alt+hotkey

Posted: Wed Oct 27, 2010 12:33 pm
by Trond
For menus it works automatically. I don't know about the buttons.

Re: Window menu Alt+hotkey

Posted: Wed Oct 27, 2010 12:42 pm
by debashisde
Does it work on Windows or it has the bug in Windows version as well?

Re: Window menu Alt+hotkey

Posted: Wed Oct 27, 2010 1:23 pm
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.

Re: Window menu Alt+hotkey

Posted: Thu Oct 28, 2010 4:07 am
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.

Re: Window menu Alt+hotkey

Posted: Thu Oct 28, 2010 8:46 am
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

Re: Window menu Alt+hotkey

Posted: Thu Oct 28, 2010 9:19 am
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.

Re: Window menu Alt+hotkey

Posted: Thu Oct 28, 2010 11:05 am
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.

Re: Window menu Alt+hotkey

Posted: Wed Nov 10, 2010 12:28 pm
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

Re: Window menu Alt+hotkey

Posted: Wed Nov 10, 2010 4:52 pm
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.