String gadget and shorcut menu

Just starting out? Need help? Post your questions and find answers here.
User avatar
[blendman]
Enthusiast
Enthusiast
Posts: 297
Joined: Thu Apr 07, 2011 1:14 pm
Location: 3 arks
Contact:

String gadget and shorcut menu

Post 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 :)
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: String gadget and shorcut menu

Post 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 :)
P.N.
Jumbuck
User
User
Posts: 63
Joined: Mon Nov 03, 2008 8:30 am
Location: Australia

Re: String gadget and shorcut menu

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4277
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: String gadget and shorcut menu

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