Page 1 of 1

CreateMenu shortcut does not work

Posted: Thu Jan 08, 2026 12:52 am
by charvista
Hi

Using:
- Windows 11 Home x64 25H2 build 26200.7462
- PureBasic 6.21 & 6.30 beta 6
This very basic shortcut (Ctrl+L and Ctrl+Q) do not seem to work. It works when you click on it, but not when doing manually Ctrl + L (or Ctrl + Q).
Can you confirm that ?

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Menu example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

;
; We just have to open a window and see when an event happen on the menu
;

If OpenWindow(0, 100, 150, 195, 260, "PureBasic - Menu")

  ;
  ; Create the menu. The indent is very important here for a good lisibility
  ;

  If CreateMenu(0, WindowID(0))
    MenuTitle("File")
      MenuItem( 1, "&Load..."+Chr(9)+"Ctrl+L")
      MenuItem( 2, "Save")
      MenuItem( 3, "Save As...")
      MenuBar()
      OpenSubMenu("Recents")
        MenuItem( 5, "Pure.png")
        MenuItem( 6, "Basic.jpg")
        OpenSubMenu("Even more !")
          MenuItem( 12, "Yeah")
        CloseSubMenu()
        MenuItem( 13, "Rocks.tga")
      CloseSubMenu()
      MenuBar()
      MenuItem( 7, "&Quit"+Chr(9)+"Ctrl+Q")

    MenuTitle("Edition")
      MenuItem( 8, "Cut")
      MenuItem( 9, "Copy")
      MenuItem(10, "Paste")
      
    MenuTitle("?")
      MenuItem(11, "About")
      MenuItem(14, "Check/Uncheck Me")

  EndIf
  
  DisableMenuItem(0, 3, 1)
  DisableMenuItem(0, 13, 1)
  
  ;
  ; This is the 'event loop'. All the user actions are processed here.
  ; It's very easy to understand: when an action occurs, the Event
  ; isn't 0 and we just have to see what have happened...
  ;
  
  Repeat

    Select WaitWindowEvent()

      Case #PB_Event_Menu

        Select EventMenu()  ; To see which menu has been selected

          Case 11 ; About
            MessageRequester("About", "Cool Menu example", 0)

          Case 14 ; Check/Uncheck Me
          If GetMenuItemState(0,14) = 1   ; Checked
            SetMenuItemState(0,14,0)      ; So uncheck Me
          Else                            ; Else
            SetMenuItemState(0,14,1)      ; Check Me
          EndIf
 
          Default
            MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)

        EndSelect

      Case #PB_Event_CloseWindow
        Quit = 1

    EndSelect

  Until Quit = 1

EndIf

End
Greetings

Re: CreateMenu shortcut does not work

Posted: Thu Jan 08, 2026 2:26 am
by RASHAD
Wake up :D

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Menu example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

;
; We just have to open a window and see when an event happen on the menu
;

If OpenWindow(0, 100, 150, 195, 260, "PureBasic - Menu")
  
  ;
  ; Create the menu. The indent is very important here for a good lisibility
  ;
  
  If CreateMenu(0, WindowID(0))
    MenuTitle("File")
    MenuItem( 1, "&Load..."+Chr(9)+"Ctrl+L")
    MenuItem( 2, "Save")
    MenuItem( 3, "Save As...")
    MenuBar()
    OpenSubMenu("Recents")
    MenuItem( 5, "Pure.png")
    MenuItem( 6, "Basic.jpg")
    OpenSubMenu("Even more !")
    MenuItem( 12, "Yeah")
    CloseSubMenu()
    MenuItem( 13, "Rocks.tga")
    CloseSubMenu()
    MenuBar()
    MenuItem( 7, "&Quit"+Chr(9)+"Ctrl+Q")
    
    MenuTitle("Edition")
    MenuItem( 8, "Cut")
    MenuItem( 9, "Copy")
    MenuItem(10, "Paste")
    
    MenuTitle("?")
    MenuItem(11, "About")
    MenuItem(14, "Check/Uncheck Me")
    
  EndIf
  
  DisableMenuItem(0, 3, 1)
  DisableMenuItem(0, 13, 1)
  
  ;
  ; This is the 'event loop'. All the user actions are processed here.
  ; It's very easy to understand: when an action occurs, the Event
  ; isn't 0 and we just have to see what have happened...
  ;
  AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_L,100)
  AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_Q,107)
  
  Repeat
    
    Select WaitWindowEvent()
        
      Case #PB_Event_Menu
        
        Select EventMenu()  ; To see which menu has been selected
            
          Case 1,100
            Debug "Load"
            
          Case 7,107
            Debug "Quit"
            
          Case 11 ; About
            MessageRequester("About", "Cool Menu example", 0)
            
          Case 14 ; Check/Uncheck Me
            If GetMenuItemState(0,14) = 1   ; Checked
              SetMenuItemState(0,14,0)      ; So uncheck Me
            Else                            ; Else
              SetMenuItemState(0,14,1)      ; Check Me
            EndIf
            
          Default
            MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)
            
        EndSelect
        
      Case #PB_Event_CloseWindow
        Quit = 1
        
    EndSelect
    
  Until Quit = 1
  
EndIf

End


Re: CreateMenu shortcut does not work [solved]

Posted: Thu Jan 08, 2026 2:55 am
by charvista
Oh, I was sleeping :D

Of course, adding AddKeyboardShortcut will solve the problem. Thanks Rashad.

The example in the Help file (Menu index) should be updated accordingly -- it is confusing, as there is an ampersand in front of the L and Q.

Re: CreateMenu shortcut does not work

Posted: Thu Jan 08, 2026 3:38 am
by charvista
Solved, yes, but not everything

I can add AddKeyboardShortcut(0, #PB_Shortcut_Alt|#PB_Shortcut_F, 99) to capture ALT+F for "&File", but how do I open the pull-down menu when it detects 99?

Re: CreateMenu shortcut does not work

Posted: Thu Jan 08, 2026 4:30 am
by RASHAD
Hi

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Menu example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

;
; We just have to open a window and see when an event happen on the menu
;

If OpenWindow(0, 100, 150, 195, 260, "PureBasic - Menu")
  
  ;
  ; Create the menu. The indent is very important here for a good lisibility
  ;
  
  If CreateMenu(0, WindowID(0))
    MenuTitle("File")
    MenuItem( 1, "&Load..."+Chr(9)+"Ctrl+L")
    MenuItem( 2, "Save")
    MenuItem( 3, "Save As...")
    MenuBar()
    OpenSubMenu("Recents")
    MenuItem( 5, "Pure.png")
    MenuItem( 6, "Basic.jpg")
    OpenSubMenu("Even more !")
    MenuItem( 12, "Yeah")
    CloseSubMenu()
    MenuItem( 13, "Rocks.tga")
    CloseSubMenu()
    MenuBar()
    MenuItem( 7, "&Quit"+Chr(9)+"Ctrl+Q")
    
    MenuTitle("Edition")
    MenuItem( 8, "Cut")
    MenuItem( 9, "Copy")
    MenuItem(10, "Paste")
    
    MenuTitle("?")
    MenuItem(11, "About")
    MenuItem(14, "Check/Uncheck Me")
    
  EndIf
  
  DisableMenuItem(0, 3, 1)
  DisableMenuItem(0, 13, 1)
  
  ;
  ; This is the 'event loop'. All the user actions are processed here.
  ; It's very easy to understand: when an action occurs, the Event
  ; isn't 0 and we just have to see what have happened...
  ;
  
  AddKeyboardShortcut(0,#PB_Shortcut_Alt|#PB_Shortcut_F, 99)
  AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_L,100)
  AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_Q,107)
  
  Repeat
    
    Select WaitWindowEvent()
        
      Case #PB_Event_Menu
        
        Select EventMenu()  ; To see which menu has been selected
            
          Case 1,100
            Debug "Load"
            
          Case 7,107
            Debug "Quit"
            
          Case 11 ; About
            MessageRequester("About", "Cool Menu example", 0)
            
          Case 14 ; Check/Uncheck Me
            If GetMenuItemState(0,14) = 1   ; Checked
              SetMenuItemState(0,14,0)      ; So uncheck Me
            Else                            ; Else
              SetMenuItemState(0,14,1)      ; Check Me
            EndIf
            
          Case 99
            GetMenuItemRect_(WindowID(0),GetMenu_(WindowID(0)),0,r.RECT)
            SetCursorPos_((r\left+5),(r\top+5))
            mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
            mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
            
          Default
            MessageRequester("Info", "MenuItem: "+Str(EventMenu()), 0)
            
        EndSelect
        
      Case #PB_Event_CloseWindow
        Quit = 1
        
    EndSelect
    
  Until Quit = 1
  
EndIf

End



Re: CreateMenu shortcut does not work [solved]

Posted: Thu Jan 08, 2026 10:44 am
by charvista
Hi RASHAD

Smart done with an API - thanks :wink: