Page 1 of 1

StringGadget Return Key (All OS)

Posted: Sat Oct 19, 2019 10:47 am
by mk-soft
Before I lose it again at all my sipped 8)

Update v1.04.1
-Bugfix macOS (Tab-Key)

Code: Select all

;-TOP

; StringGadget ReturnKey by mk-soft, Version v1.04.1

; ----

CompilerIf #PB_Compiler_Version >= 572
  #PB_EventType_ReturnKey = $501 ; SDK Event.h
CompilerEndIf

#MenuEvent_ReturnKey = 10000

Procedure DoEventGadgetType()
  Protected gadget = EventGadget()
  If IsGadget(gadget)
    Select GadgetType(gadget)
      Case #PB_GadgetType_String
        Select EventType()
          Case #PB_EventType_Focus
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
              ; Bugfix macOS event order with 'tab' key
              If EventData() = #False
                PostEvent(#PB_Event_Gadget, EventWindow(), EventGadget(), #PB_EventType_Focus, #True)
              Else
                AddKeyboardShortcut(0, #PB_Shortcut_Return, #MenuEvent_ReturnKey)
              EndIf
            CompilerElse
              AddKeyboardShortcut(0, #PB_Shortcut_Return, #MenuEvent_ReturnKey)
            CompilerEndIf
          Case #PB_EventType_LostFocus
            RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
        EndSelect
    EndSelect
  EndIf
EndProcedure

Procedure DoEventReturnKey()
  PostEvent(#PB_Event_Gadget, GetActiveWindow(), GetActiveGadget(), #PB_EventType_ReturnKey)
EndProcedure

; ****

CompilerIf #PB_Compiler_IsMainFile
  
  If OpenWindow(0, 0, 0, 400, 300, "StringGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget(0, 10, 10, 380, 30, "StringGadget 1")
    StringGadget(1, 10, 50, 380, 30, "StringGadget 2")
    EditorGadget(2, 10, 90, 380, 190)
    
    CreateMenu(0, WindowID(0))
    BindEvent(#PB_Event_Gadget, @DoEventGadgetType())
    BindMenuEvent(0, #MenuEvent_ReturnKey, @DoEventReturnKey())
    
    SetActiveGadget(0)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 0
              Select EventType()
                Case #PB_EventType_ReturnKey
                  Debug "Return Gadget 0"
                  ;SetActiveGadget(1)
              EndSelect
              
            Case 1
              Select EventType()
                Case #PB_EventType_ReturnKey
                  Debug "Return Gadget 1"
                  ;SetActiveGadget(2)
              EndSelect
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
CompilerEndIf
[/size]

Re: StringGadget Return Key (All OS)

Posted: Sun Oct 20, 2019 1:54 am
by skywalk
Thanks mk-soft! 8)
I added a stringgadget input field to a canvasgadget container on a scrollareagadget and this is more elegant at managing the hotkeys. :oops:

Re: StringGadget Return Key (All OS)

Posted: Thu Aug 13, 2020 5:29 pm
by mk-soft
Update v1.04
-Bugfix macOS (Tab-Key)

Re: StringGadget Return Key (All OS)

Posted: Fri Aug 21, 2020 6:55 pm
by Kwai chang caine
Can be usefull, works nice here
Thanks for sharing 8)

Re: StringGadget Return Key (All OS)

Posted: Sat Aug 22, 2020 1:33 pm
by ShadowStorm
Hello, I don't understand what this is for!

Re: StringGadget Return Key (All OS)

Posted: Sun Aug 23, 2020 2:49 pm
by mk-soft
The PB StringGadget don't support the EventType ReturnKey. Only the EventType Change, Focus and LostFocus

Re: StringGadget Return Key (All OS)

Posted: Sat Sep 12, 2020 9:30 am
by Jac de Lad
So wouldn't it be easier to define a hotkey and check if the Stringgadget has the focus? That's how I do it.

Re: StringGadget Return Key (All OS)

Posted: Sat Sep 12, 2020 10:47 am
by mk-soft
Jac de Lad wrote:So wouldn't it be easier to define a hotkey and check if the Stringgadget has the focus? That's how I do it.
But this way you steal the ReturnKey from the EditorGadget

Re: StringGadget Return Key (All OS)

Posted: Sat Sep 12, 2020 11:35 am
by Jac de Lad
My fault. I was thinking about Stringgadgets.