Page 1 of 1
Stumped
Posted: Tue Mar 11, 2008 6:57 pm
by Tech-Man
Hi all, soz if this is a stupid question, but is there anyway to change the gadgetbox's input?
i.e i want to move to the next gadgetstringbox with return key and not the tab key..
TIA..
Posted: Tue Mar 11, 2008 7:04 pm
by Fluid Byte
Code: Select all
Enumeration
#STR_EditCtrl1
#STR_EditCtrl2
#STR_EditCtrl3
#STR_EditCtrl4
#BTN_Untitled1
EndEnumeration
#IDM_ReturnKey = 101
OpenWindow(0,0,0,320,240,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
StringGadget(#STR_EditCtrl1,5,5,250,20,"untitled1")
StringGadget(#STR_EditCtrl2,5,35,250,20,"untitled2")
StringGadget(#STR_EditCtrl3,5,65,250,20,"untitled3")
StringGadget(#STR_EditCtrl4,5,90,250,20,"untitled4")
ButtonGadget(#BTN_Untitled1,5,120,120,25,"untiled")
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
If EventType() = #PB_EventType_Focus And EventGadget() >= #STR_EditCtrl1 And EventGadget() < #STR_EditCtrl4
AddKeyboardShortcut(0,#PB_Shortcut_Return,#IDM_ReturnKey)
Else
RemoveKeyboardShortcut(0,#PB_Shortcut_Return)
EndIf
EndIf
If EventID = #PB_Event_Menu
Index = GetActiveGadget()
If Index = #STR_EditCtrl4
SetActiveGadget(#STR_EditCtrl1)
Else
SetActiveGadget(Index + 1)
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
Posted: Tue Mar 11, 2008 7:21 pm
by Derek
If you don't mind some api then this puts the cursor at the end of the string input when tabbing, seems more natural.
Code: Select all
Enumeration
#STR_EditCtrl1
#STR_EditCtrl2
#STR_EditCtrl3
#STR_EditCtrl4
EndEnumeration
#IDM_ReturnKey = 101
OpenWindow(0,0,0,320,240,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
StringGadget(#STR_EditCtrl1,5,5,250,20,"untitled1")
StringGadget(#STR_EditCtrl2,5,35,250,20,"untitled2")
StringGadget(#STR_EditCtrl3,5,65,250,20,"untitled3")
StringGadget(#STR_EditCtrl4,5,90,250,20,"untitled4")
AddKeyboardShortcut(0,#PB_Shortcut_Return,#IDM_ReturnKey)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Menu
Index = GetActiveGadget()
If Index = #STR_EditCtrl4
SetActiveGadget(#STR_EditCtrl1)
Else
SetActiveGadget(Index + 1)
EndIf
l=Len(GetGadgetText(GetActiveGadget()))
SendMessage_(GadgetID(GetActiveGadget()),#EM_SETSEL,l,l)
EndIf
Until EventID = #PB_Event_CloseWindow
Posted: Wed Mar 12, 2008 10:06 am
by Tech-Man
Thanks guys works fine
I knew there had to be a simple way....
Strangly tho when I add , #PB_String_Numeric to the end for non-text input it stops working?
is this a normal action or a bug?
(
update: it doesnt work after you entered any values in

have to tab to next box)
Basically this is reading input from a barcode reader which automatically put's a CR/LF after reading the barcode, and i needed it to goto the next box/gadget after.
TIA
TM.
Posted: Wed Mar 12, 2008 10:35 am
by ABBKlaus
Heres my version (including bugfix) :
Code: Select all
Enumeration
#STR_EditCtrl1
#STR_EditCtrl2
#STR_EditCtrl3
#STR_EditCtrl4
#BTN_Untitled1
#STR_EditCtrl5
EndEnumeration
#IDM_ReturnKey = 101
OpenWindow(0,0,0,320,240,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
StringGadget(#STR_EditCtrl1,5,5,250,20,"untitled1",#PB_String_Numeric)
StringGadget(#STR_EditCtrl2,5,35,250,20,"untitled2",#PB_String_Numeric)
StringGadget(#STR_EditCtrl3,5,65,250,20,"untitled3",#PB_String_Numeric)
StringGadget(#STR_EditCtrl4,5,90,250,20,"untitled4",#PB_String_Numeric)
ButtonGadget(#BTN_Untitled1,5,120,120,25,"untiled",#PB_String_Numeric)
StringGadget(#STR_EditCtrl5,5,155,250,20,"untitled5")
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
If EventType() = #PB_EventType_Focus And GadgetType(EventGadget())=#PB_GadgetType_String
AddKeyboardShortcut(0,#PB_Shortcut_Return,#IDM_ReturnKey)
Debug "AddKeyboardShortcut"
ElseIf EventType() = #PB_EventType_LostFocus And GadgetType(EventGadget())=#PB_GadgetType_String
RemoveKeyboardShortcut(0,#PB_Shortcut_Return)
Debug "RemoveKeyboardShortcut"
EndIf
EndIf
If EventID = #PB_Event_Menu And EventMenu()=#IDM_ReturnKey
Index = GetActiveGadget()
If Index = #STR_EditCtrl4
SetActiveGadget(#STR_EditCtrl1)
ElseIf IsGadget(Index + 1)
SetActiveGadget(Index + 1)
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
Edited : example is now more bulletproof
Posted: Wed Mar 12, 2008 10:45 am
by Tech-Man
Thank ABBKlaus,
Works 100%

I can sleep easy now lol
TM.
Posted: Wed Mar 12, 2008 11:10 am
by Fluid Byte
ABBKlaus wrote:Heres my version (including bugfix) :
There wasn't anything to bugfix until you changed it.
First you don't need to asign #PB_String_Numeric to a button and second the code fails if you add another StringGadget() because you removed the ID range check.
@Tech-Man:
Use my original version and add your flags and you're good to go:
Code: Select all
Enumeration
#STR_EditCtrl1
#STR_EditCtrl2
#STR_EditCtrl3
#STR_EditCtrl4
#BTN_Untitled1
#STR_EditCtrl5
EndEnumeration
#IDM_ReturnKey = 101
OpenWindow(0,0,0,320,240,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
StringGadget(#STR_EditCtrl1,5,5,250,20,"untitled1",#PB_String_Numeric)
StringGadget(#STR_EditCtrl2,5,35,250,20,"untitled2",#PB_String_Numeric)
StringGadget(#STR_EditCtrl3,5,65,250,20,"untitled3",#PB_String_Numeric)
StringGadget(#STR_EditCtrl4,5,90,250,20,"untitled4",#PB_String_Numeric)
ButtonGadget(#BTN_Untitled1,5,120,120,25,"untiled")
StringGadget(#STR_EditCtrl5,5,150,250,25,"untiled5",#PB_String_Numeric)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
If EventType() = #PB_EventType_Focus And EventGadget() >= #STR_EditCtrl1 And EventGadget() <= #STR_EditCtrl4
AddKeyboardShortcut(0,#PB_Shortcut_Return,#IDM_ReturnKey)
ElseIf EventType() = #PB_EventType_LostFocus
RemoveKeyboardShortcut(0,#PB_Shortcut_Return)
EndIf
EndIf
If EventID = #PB_Event_Menu And EventMenu() = #IDM_ReturnKey
Index = GetActiveGadget()
If Index = #STR_EditCtrl4
SetActiveGadget(#STR_EditCtrl1)
Else
SetActiveGadget(Index + 1)
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
Posted: Wed Mar 12, 2008 12:04 pm
by ABBKlaus
Your code is not working fluid

You are removing the keyboard shortcut too early.
Posted: Wed Mar 12, 2008 1:26 pm
by Fluid Byte
ABBKlaus wrote:Your code is not working fluid

You are removing the keyboard shortcut too early.
Can't confirm that, it's working flawlessly here (WindowsXP SP2 / PB4.20b).
Posted: Wed Mar 12, 2008 2:23 pm
by ABBKlaus
Did you tried entering some text in a stringgadget and then pressing enter ?
Posted: Wed Mar 12, 2008 2:40 pm
by Kaeru Gaman
You're right, Klaus
you can even read it from the code only:
Code: Select all
If EventID = #PB_Event_Gadget
If EventType() =
AddKeyboardShortcut(0,#PB_Shortcut_Return,#IDM_ReturnKey)
Else
;*****************************************
RemoveKeyboardShortcut(0,#PB_Shortcut_Return)
;*****************************************
EndIf
EndIf
removing the shortcut on any not special gadget event.
it cannot work at all.
additionally, not a single keytype is accepted by any gadget.
Posted: Wed Mar 12, 2008 3:08 pm
by Fluid Byte
Ok, now I see what you mean. You just need to check for #PB_EventType_LostFocus and it's working again. Nevertheless you shouldn't remove the ID range check.