Welcome, Guest. Please login or register.

Author Topic: Problem with AddKeyboardShortcut()  (Read 23 times)

Offline Columbo

  • Administrator
  • Hero Member
  • *****
  • Posts: 511
  • Basic is alive and well!
    • View Profile
    • Divi-Help (For Divi Builder users.
Problem with AddKeyboardShortcut()
« on: May 07, 2019, 03:56:41 PM »
I'm having a problem getting my AddKeyboardShortcut() to work.  I want the user to be able to type a string into the StringGadget which is my #searchBox. This is the code that I used in the window setup:

Code: [Select]
wFlags = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget           ;Window flags
If OpenWindow(#MainWindow, 0, 0, 1280, 700, "", wFlags)     ;Open Main Window
  SetWindowColor(#MainWindow, RGB(255,255,255))
  AddKeyboardShortcut(#MainWindow, #PB_Shortcut_Return, #kbdSearch)     ;Trap keyboard input
 EndIf

This is the StringGadget:

Code: [Select]

 Procedure setupscreenMain()
  LoadFont(#searchFont,"Arial",11)   
  ImageGadget(#header,0,0,1206,180,ImageID(#img1))
  DisableGadget(#header,1)
  ImageGadget(#footer,0,667,1206,30,ImageID(#img2))
  ButtonImageGadget(#homeBtn, 250, 161, 99,30, ImageID(#img3))
  ButtonImageGadget(#categoriesBtn, 350, 161, 99,30, ImageID(#img5))
  ButtonImageGadget(#favouritesBtn, 450, 161, 99,30, ImageID(#img7))   
  ButtonImageGadget(#addBtn, 550, 161, 99,30, ImageID(#img9))
  ButtonImageGadget(#addCatBtn, 650, 161, 99,30, ImageID(#img30))
  ButtonImageGadget(#exitBtn, 750, 161, 99,30, ImageID(#img13))
  StringGadget(#searchBox,999, 51, 206, 25,"",#SS_CENTERIMAGE)     ; <---  The search box
  ButtonImageGadget(#searchBtn, 1212, 50, 37,26, ImageID(#searchBtn))
  SetGadgetFont(#searchBox, FontID(#searchFont))
  SetActiveGadget(#searchBox)
 
EndProcedure


And this is where I capture the event:

Code: [Select]

Repeat
    Select WaitWindowEvent()                  ;Wait for an event         
       
      Case #PB_Event_CloseWindow          ;Close window if "X" is clicked.
        run = 1                           ;Set run flag To 1       
       
       Case #PB_Event_Menu       
         Select EventMenu()
           Case #kbdSearch                   ;Check for keyboard event.
             If GetActiveGadget() = #searchBox   ;Check if searchBox box is being used.
                    hidethegadgets()
                    search()
                    HideGadget(#labelsearchLV,0)
                    HideGadget(#LVsearch,0)
                    HideGadget(#searchSelectBtn,0)
                    HideGadget(#searchCancelBtn,0)
                    SetGadgetText(#searchBox, "")          ;Clear the last search string from search box.
                    populateSearchList()
                EndIf                         
       EndSelect
       
       Select EventWindow()     
        Case #MainWindow           ;If the event is from the MainWindow
          run = 1                  ;Set run flag to 1
             
       EndSelect
       
              Case #PB_Event_Gadget
                Select EventGadget()
                    .....
                    .....


I used this same code in a previous program and it works fine.  In my current program, when I type a string into the StringGadget and press the enter key the program just quits.  Its like I had clicked the 'X' in the window.  I have placed debugs all the way through the steps and althoughy the searchString is correct, and the database finds the recipes, the Listview is not visible.  If I do a IsWindowVisible_(GadgetID(#LVsearch)) I get a 1 indicating that it is visible.

Any ideas?

« Last Edit: May 07, 2019, 04:31:29 PM by Columbo »
New forum for DIVI Builder users. - http://www.divi-help.com

Offline TI-994A

  • Sr. Member
  • ***
  • Posts: 242
  • You can do it in BASIC!
    • View Profile
Re: Problem with AddKeyboardShortcut()
« Reply #1 on: May 07, 2019, 07:27:48 PM »
Code: [Select]
Repeat
    Select WaitWindowEvent()                  ;Wait for an event         
       
      Case #PB_Event_CloseWindow          ;Close window if "X" is clicked.
        run = 1                           ;Set run flag To 1       
       
       Case #PB_Event_Menu       
         Select EventMenu()
           Case #kbdSearch                   ;Check for keyboard event.
             If GetActiveGadget() = #searchBox   ;Check if searchBox box is being used.
                    hidethegadgets()
                    search()
                    HideGadget(#labelsearchLV,0)
                    HideGadget(#LVsearch,0)
                    HideGadget(#searchSelectBtn,0)
                    HideGadget(#searchCancelBtn,0)
                    SetGadgetText(#searchBox, "")          ;Clear the last search string from search box.
                    populateSearchList()
                EndIf                         
       EndSelect
       
       Select EventWindow()     
        Case #MainWindow           ;If the event is from the MainWindow
          run = 1                  ;Set run flag to 1
             
       EndSelect
       
              Case #PB_Event_Gadget
                Select EventGadget()
                    .....
                    .....


...when I type a string into the StringGadget and press the enter key the program just quits.

Hi John. The app-quit flag (run) is being set whenever the return key is intercepted, because the EventWindow() check is under the #PB_Event_Menu case. Simply move that validation block up into the #PB_Event_CloseWindow case and it should stop quitting on the return key.

Code: [Select]
Repeat
  Select WaitWindowEvent()                  ;Wait for an event         
     
    Case #PB_Event_CloseWindow          ;Close window if "X" is clicked.
      ;run = 1                           ;Set run flag To 1       
     
      Select EventWindow()     
        Case #MainWindow           ;If the event is from the MainWindow
          run = 1                  ;Set run flag to 1
         
      EndSelect     
     
    Case #PB_Event_Menu       
      Select EventMenu()
        Case #kbdSearch                   ;Check for keyboard event.
          If GetActiveGadget() = #searchBox   ;Check if searchBox box is being used.
            hidethegadgets()
            search()
            HideGadget(#labelsearchLV,0)
            HideGadget(#LVsearch,0)
            HideGadget(#searchSelectBtn,0)
            HideGadget(#searchCancelBtn,0)
            SetGadgetText(#searchBox, "")          ;Clear the last search string from search box.
            populateSearchList()
          EndIf                         
      EndSelect
     
    Case #PB_Event_Gadget
      Select EventGadget()
          .....
          .....
Texas Instruments 99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!

Offline Columbo

  • Administrator
  • Hero Member
  • *****
  • Posts: 511
  • Basic is alive and well!
    • View Profile
    • Divi-Help (For Divi Builder users.
Re: Problem with AddKeyboardShortcut()
« Reply #2 on: May 07, 2019, 11:07:24 PM »
Thanks Syed,  Works now.  That had me really baffles since the actual code was identical to the code I used in my PrehistoricLife program.  It worked there but not in this program.

Cheers!

John

New forum for DIVI Builder users. - http://www.divi-help.com