StringGadget Return Key (All OS)

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 6249
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

StringGadget Return Key (All OS)

Post 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]
Last edited by mk-soft on Thu Aug 13, 2020 5:50 pm, edited 3 times in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
skywalk
Addict
Addict
Posts: 4218
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: StringGadget Return Key (All OS)

Post 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:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
mk-soft
Always Here
Always Here
Posts: 6249
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: StringGadget Return Key (All OS)

Post by mk-soft »

Update v1.04
-Bugfix macOS (Tab-Key)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: StringGadget Return Key (All OS)

Post by Kwai chang caine »

Can be usefull, works nice here
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
ShadowStorm
Enthusiast
Enthusiast
Posts: 303
Joined: Tue Feb 14, 2017 12:07 pm

Re: StringGadget Return Key (All OS)

Post by ShadowStorm »

Hello, I don't understand what this is for!
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
User avatar
mk-soft
Always Here
Always Here
Posts: 6249
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: StringGadget Return Key (All OS)

Post by mk-soft »

The PB StringGadget don't support the EventType ReturnKey. Only the EventType Change, Focus and LostFocus
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: StringGadget Return Key (All OS)

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6249
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: StringGadget Return Key (All OS)

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: StringGadget Return Key (All OS)

Post by Jac de Lad »

My fault. I was thinking about Stringgadgets.
Post Reply