I have a strange situation that I didn't think through.
One a form, I have an editorgadget and a stringgadget. I have attached a Return key shortcut to the form (Wasn't thinking) which triggers a search of the editorgadget but of course then Return no longer goes to a new line in the editorgadget.
Has anyone had this problem before and thought of a better way to do this?
Return in StringGadget stops EditorGadget newline
- Fangbeast
- PureBasic Protozoa
- Posts: 4749
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Return in StringGadget stops EditorGadget newline
Amateur Radio, D-STAR/VK3HAF
Re: Return in StringGadget stops EditorGadget newline
Here's one way:
Code: Select all
Global EventTyp.l, liveWin, lastLiveWin
#KB_Return = #PB_Shortcut_Return + 49152
Procedure KeyboardGyration()
Select EventType()
Case #PB_EventType_Focus
Debug "focus on window " + Str(liveWin)
AddKeyboardShortcut(liveWin, #PB_Shortcut_Return, #KB_Return)
lastLiveWin = liveWin
Case #PB_EventType_LostFocus
Debug "lost focus on window " + Str(lastLiveWin)
RemoveKeyboardShortcut(lastLiveWin, #PB_Shortcut_Return)
EndSelect
EndProcedure
OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(0, 110,20,300,20,"")
EditorGadget(1,10,50,400,400)
SetActiveGadget(0)
OpenWindow(2,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(2, 110,20,300,20,"")
EditorGadget(3,10,50,400,400)
SetActiveGadget(2)
Repeat
EventID = WaitWindowEvent()
liveWin = GetActiveWindow()
Select EventID
Case #PB_Event_Gadget ;only one gadget list for all windows
EventTyp.l = EventType()
Select EventGadget()
Case 0, 2
KeyboardGyration()
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #KB_Return
Select liveWin ;menu events can take place on different windows
Case 0
SetActiveGadget(1)
Case 1
SetActiveGadget(3)
EndSelect
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
Re: Return in StringGadget stops EditorGadget newline
Hi Fang
Simple as usual
Simple as usual
Code: Select all
If OpenWindow(0, 0, 0, 300, 200, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0,10,10,280,24,"OK")
EditorGadget(1, 10, 45, 280,130,#PB_Editor_WordWrap)
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Select EventMenu()
Case 10
If GetActiveGadget() = 0
SetActiveGadget(1)
EndIf
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 0
AddKeyboardShortcut(0,#PB_Shortcut_Return,10)
Case 1
RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
EndSelect
EndSelect
Until Quit = 1
EndIf
Egypt my love
Re: Return in StringGadget stops EditorGadget newline
Only depending on the StringGadget itself:
Code: Select all
If OpenWindow(0, 0, 0, 300, 200, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0,10,10,280,24,"OK")
EditorGadget(1, 10, 45, 280,130,#PB_Editor_WordWrap)
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Select EventMenu()
Case 10
Debug "Shortcut from StringGadget"
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_Focus
AddKeyboardShortcut(0,#PB_Shortcut_Return,10)
Case #PB_EventType_LostFocus
RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
EndSelect
EndSelect
EndSelect
Until Quit = 1
EndIf
- Fangbeast
- PureBasic Protozoa
- Posts: 4749
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Return in StringGadget stops EditorGadget newline
I suspected that adding and removing the shortcut might work but at 11:30 at night, it was too late to try it.
Us old folks need our beauty sleep after all.
Thanks for the nice examples folks, I didn't think things through properly.
Us old folks need our beauty sleep after all.
Thanks for the nice examples folks, I didn't think things through properly.
Amateur Radio, D-STAR/VK3HAF