Page 1 of 1

StringGadget () EventTypes

Posted: Thu Nov 09, 2017 12:01 pm
by Dirk Geppert
Hello Fred,

to finish an input in StringGadegt by pressing Enter, it would be nice if this would also support #PB_EventType_ReturnKey.

Ciao Dirk

Re: StringGadget () EventTypes

Posted: Thu Nov 09, 2017 12:20 pm
by Peter
Hello Dirk,

for this one we have the AddKeyboardShortcut()-Command

Code: Select all

Enumeration
  
  #sg1
  #sg2
  #sg3
  
  #ShortcutReturnEvent
  
EndEnumeration

Procedure MenuEvents()
  
  Select EventMenu()
    Case #ShortcutReturnEvent
      Select GetActiveGadget()
        Case #sg1
          Debug "ReturnKey on #sg1"
        Case #sg2
          Debug "ReturnKey on #sg2"
        Case #sg3
          Debug "ReturnKey on #sg3"
      EndSelect
  EndSelect
  
EndProcedure

OpenWindow(0, 0, 0, 322, 105, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(#sg1, 8,  10, 306, 20, "")
StringGadget(#sg2, 8,  35, 306, 20, "")
StringGadget(#sg3, 8,  60, 306, 20, "")

AddKeyboardShortcut(0, #PB_Shortcut_Return, #ShortcutReturnEvent)
BindEvent(#PB_Event_Menu, @MenuEvents())
Greetings ... Peter

Edit:

Alternatively, you can use the GadgetEventEx-Module (https://github.com/spiderbytes/GadgetEventEx)

Code: Select all

XIncludeFile "GadgetEventEx.sbi"

Enumeration
  #Window
  #StringGadget
EndEnumeration

Procedure KeyUpEvent(e)
  
  Protected Which
  ! v_which = v_e.which;
  
  If Which = #CR
    Debug "ReturnKey-Event from #StringGadget: " + EventGadget()
  EndIf
  
EndProcedure

OpenWindow(#Window, 0, 0, 300, 300, "GadgetEventExDemo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(#StringGadget, 10, 10, 100, 20, "StringGadget")
GadgetEventEx::Bind(#StringGadget, @KeyUpEvent(), "keyup")

Re: StringGadget () EventTypes

Posted: Fri Nov 10, 2017 9:57 am
by Dirk Geppert
Thanks Peter!