Stumped

Just starting out? Need help? Post your questions and find answers here.
Tech-Man
New User
New User
Posts: 9
Joined: Fri Aug 08, 2003 7:52 pm

Stumped

Post 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..
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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
Tech-Man
New User
New User
Posts: 9
Joined: Fri Aug 08, 2003 7:52 pm

Post by Tech-Man »

Thanks guys works fine :D

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.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post 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
Last edited by ABBKlaus on Wed Mar 12, 2008 2:54 pm, edited 1 time in total.
Tech-Man
New User
New User
Posts: 9
Joined: Fri Aug 08, 2003 7:52 pm

Post by Tech-Man »

Thank ABBKlaus,

Works 100% :D
I can sleep easy now lol ;)

TM.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

ABBKlaus wrote:Heres my version (including bugfix) :
There wasn't anything to bugfix until you changed it. :wink:

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
Last edited by Fluid Byte on Wed Mar 12, 2008 3:05 pm, edited 1 time in total.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

Your code is not working fluid :wink: You are removing the keyboard shortcut too early.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

ABBKlaus wrote:Your code is not working fluid :wink: You are removing the keyboard shortcut too early.
Can't confirm that, it's working flawlessly here (WindowsXP SP2 / PB4.20b).
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

Did you tried entering some text in a stringgadget and then pressing enter ?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Post Reply