#PB_Shortcut_Return, #kbdEnter with EditorGadget()

Just starting out? Need help? Post your questions and find answers here.
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

#PB_Shortcut_Return, #kbdEnter with EditorGadget()

Post by Columbo »

Does the AddKeyboardShortcut( #mainWindow, #PB_Shortcut_Return, #kbdEnterKey) not work in an EditorGadget? I added this shortcut to the main window and if I press the <Enter> key when the EditorGadget is the active gadget, I want it to call the saveData() procedure.

I tried this and when I enter some data into the editor gadget and I pressed <Enter> it just inserts a blank line in the EditorGadget instead of calling saveData().

Here is the code that I used:

Code: Select all

OpenWindow(#mainWindow, 0, 0, 780, 498, "", wFlags)
  SetWindowColor(#mainWindow, RGB(245,245,245))
  AddKeyboardShortcut( #mainWindow, #PB_Shortcut_Return, #kbdEnterKey)
  
  setupMainScreen()
  
    ;--------[ Wait for window event ]--------
  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 #kbdEnterKey
            result = GetActiveGadget()
            If result = 14   ;14 is the #editorFLD gadget
              saveData()
              clearGadgets()
            EndIf
        EndSelect  
        
      Case #PB_Event_Gadget      ;Check for gadget event
        Select EventGadget()
           ......
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: #PB_Shortcut_Return, #kbdEnter with EditorGadget()

Post by TI-994A »

Columbo wrote:...shortcut to the main window and if I press the <Enter> key when the EditorGadget is the active gadget, I want it to call the saveData() procedure...
Hi John. The posted code appears procedurally sound. Perhaps some discrepancy with the constant values. Try this:

Code: Select all

#mainWindow = 0
#editorGadget = 0
#kbdEnterKey = 0

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(0, 0, 0, 300, 200, "EditorGadget Return", wFlags)
  EditorGadget (#editorGadget, 10, 10, 280, 180)
  AddKeyboardShortcut(#mainWindow, #PB_Shortcut_Return, #kbdEnterKey)
  SetActiveGadget(#editorGadget)  
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #PB_Event_CloseWindow
        appQuit = #True
      Case #PB_Event_Menu
        Select EventMenu()
          Case #kbdEnterKey
            If GetActiveGadget() = #editorGadget
              MessageRequester("EditorGadget", "Call saveData() procedure...")
            EndIf
        EndSelect
    EndSelect
  Until appQuit
EndIf
Texas Instruments TI-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! Please visit my YouTube Channel :D
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: #PB_Shortcut_Return, #kbdEnter with EditorGadget()

Post by Columbo »

Thanks Syed, much appreciated.
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
Post Reply