Page 1 of 1

String gadget and shorcut menu

Posted: Thu May 03, 2012 6:10 pm
by [blendman]
Hi

How can I use all the key with shortcut menu, please ?

If I try to tape the B key, it doesn't work.

Code: Select all

Enumeration
  #Win_0
EndEnumeration

flag = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_WindowCentered
If OpenWindow(#Win_0, 0,0,800, 600, "Shorcut & String gadget", flag)
 
  CreateMenu(0,WindowID(#win_0))
  MenuTitle("File")
  MenuItem(0,"test")
 
  AddKeyboardShortcut(0,#PB_Shortcut_B,0)
 
  StringGadget(0,10,10,120,20,"")
EndIf


Repeat
  EventID  =WaitWindowEvent()
 
  Select EventID
    Case #PB_Event_Menu
      Select EventMenu()
        Case 0
          If focus = 0
            MessageRequester("info","just to test the menu")
          EndIf
         
      EndSelect
     
    Case #PB_Event_CloseWindow
      quit=1
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_Focus
              focus = 1
             
            Case #PB_EventType_LostFocus
              focus = 0
             
            Case #PB_EventType_Change
              Debug GetGadgetText(0) ; please try to type the B key !
             
          EndSelect
         
      EndSelect
           
  EndSelect
 
Until quit
End
Any idea ?

Thank you :)

Re: String gadget and shorcut menu

Posted: Thu May 03, 2012 6:29 pm
by Pot Noodle
Hi [blendman], I may be totaly wrong here and way off but looking at
AddKeyboardShortcut(0,#PB_Shortcut_B,0)
Try this "AddKeyboardShortcut(0,#PB_Shortcut_B,15)"
Hope it works for you :)

Re: String gadget and shorcut menu

Posted: Sat May 05, 2012 11:35 am
by Jumbuck
Hi Blendman,
Try this.

Code: Select all

Enumeration 1  
 #Win_0
 EndEnumeration
 #WindowIndex = #PB_Compiler_EnumerationValue ; Next window value will be the last used plus 1 
 
 Enumeration 1
 ;All ShortCuts 
 #Shortcut_Menu_Test
 EndEnumeration
 #MenuIndex = #PB_Compiler_EnumerationValue ; Next window value will be the last used plus 1 
 
 Enumeration 1
 ;Normal StringGadgets
 #Gadget_0
 EndEnumeration 
 #GadgetIndex = #PB_Compiler_EnumerationValue ; Next gadget value will be the last used plus 1 
 
    flag = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_WindowCentered
    If OpenWindow(#Win_0, 0,0,800, 600, "Shorcut & String gadget", flag)
     
      CreateMenu(#Win_0,WindowID(#Win_0))
      MenuTitle("File")
      MenuItem(0,"&Test")
     
      AddKeyboardShortcut(#Win_0,#PB_Shortcut_T,#Shortcut_Menu_Test)
      StringGadget(#Gadget_0,10,10,120,20,"")
    EndIf


    Repeat
      EventID  =WaitWindowEvent()
     
      Select EventID
        Case #PB_Event_Menu
          Select EventMenu()
            Case 0
              If focus = 0
                MessageRequester("info","just to test the menu")
              EndIf
             
          EndSelect
         
        Case #PB_Event_CloseWindow
          quit=1
         
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 0
              Select EventType()
                Case #PB_EventType_Focus
                  focus = 1
                 
                Case #PB_EventType_LostFocus
                  focus = 0
                 
                Case #PB_EventType_Change
                  Debug GetGadgetText(0) ; please try to type the T key !
                 
              EndSelect
             
          EndSelect
               
      EndSelect
     
    Until quit
    End

Re: String gadget and shorcut menu

Posted: Sat May 05, 2012 3:26 pm
by Demivec
[blendman] wrote:How can I use all the key with shortcut menu, please ?

If I try to tape the B key, it doesn't work.
You've set the Shortcut-B to only do something if the string gadget doesn't have focus. You have only one gadget, which means if you select it you can't cause it to lose keyboard focus by selecting anything else in your window.

You can still use the shortcut if you select the menu option before selecting the string gadget. You'll notice the event is being handled even when the StringGadget is active (it absorbs the 'B' before the string gadget gets it but the 'focus' variable won't let it display anything until the StringGadget loses focus first).

If the problem is that the window doesn't have keyboard focus at first, you will need to click on it somewhere, outside of the stringGadget (which won't give up it's focus) first.