Textfield not registering ReturnArchives Forums/BlitzPlus Bug Reports/Textfield not registering Return
| Righty, here's the code:|
pseudo_group_window = CreateWindow("Select Name For Group",ClientWidth(Desktop())/2,ClientHeight(Desktop())/2,256,128,0,1) pseudo_group_textfield = CreateTextField (16,16,ClientWidth(pseudo_group_window)-32,16,pseudo_group_window) SetGadgetText (pseudo_group_textfield,"hello") Repeat id=WaitEvent() DebugLog "Event = $"+Right$(Hex$(id),4) + " "+EventSource() + " "+EventData() Select id Case EVENT_GADGET If EventSource() = pseudo_group_textfield SetGadgetText (pseudo_group_label,EventData()) If EventData() = 13 Stop Exit EndIf EndIf End Select Forever
When I press return in the text box I get an event ID of $104 (wtf?!) and EventSource and EventData of 0.
Windows XP Professional, SP2
| Checkout the online help here:|
The style flag needs to be 4 and then you can get the event from the button itself using:
If EventData() = 13
| Actually i've set the style flag to 4 but i'm still unable to get the eventdata()=13|
| You can use this code to capture a return key press|
win = CreateWindow("Test Window - Default (15)",0,500,400,100,0) tbox = CreateTextArea(0,0,200,200,win) ; wait until the user closes one of the windows HotKeyEvent 28,0,$028,0,0,0,0,win; Set EventCode to $028 for enter key Repeat id = WaitEvent() Select id Case $028; Trap Enter key press here Stop Case $803 Exit End Select Forever End ; bye!
| The previous code actually doesn't work on a text field and you are right there is a BUG in the text field.. They do not return a eventsource ID when you select them, they only return something when you actually enter something in to them other than the enter key press. But once you enter something in to them you can trap the enter key.. Here is my revised code I've been working on trynig to figure out how to get this to work. Hope it helps you some.|
dType = False win = CreateWindow("test",0,500,400,400,0) tbox = CreateTextArea(0,0,200,100,win) gbox = CreateTextField(0,102,200,20,win) HotKeyEvent 28,0,$028,0,0,0,0,win Repeat id = WaitEvent() Select id Case $028 If (Not dType) id = 0:Goto badreturnkeypress Stop Case 260; ENTER Key press ID when in a text field If (Not dType) id = 0:Goto badreturnkeypress Stop Case $401 dType = False If (Not dType) And EventSource() = tbox dType = True:Stop If (Not dType) And EventSource() = gbox dType = True Case $803 Exit .badreturnkeypress End Select Forever End
| The only problem is if the user didn't press any key on the gadget - it will not know which gadget is in!|
As i cannot get event activity for user selecting a gadget i'm unable to try get around this problem!
But thanks anyway - If the user would not change gadget with mouse i might be able to cycle the gadgets in a predefined manner...
I know there is tab - but tab does'nt generate any event either and i must process the contents of the string conditionally or do maths operation depending on the textfield...
| I don't see a problem with using my solution.. Simply keep to sets of variables and after an ENTER is detected compare the two sets of variables to see what data was changed and then act accordingly.|
But I do think they need to fix this bug so we don't need to add all the extra code to do something that should be very simple.
| The code i have needs to check the textfield contents on the press of the return key, and if valid it will perform some actions or operations and activate the corresponding textfield result.|
I did a workaround, and set a gadget variable that keeps track of all relevant events and is updated to the relevant gadget use by the use of the escape key.
Of course the user has to type something into the gadget the first time he uses. Selecting the gadget does not produce any eventid()...
Still it was best if the return key press eventid produced more data - at least the eventsource() data...
| I hope I understood your problem in the right way. Your problem is, that, after an update I suspect, the textfields don't register EventData 13 anymore when the return-key is pressed. I had the same problem after an update from version 1.11 to version 1.45 and I solved it in this way:|
-Create a Button next to the textfield with style flag 4.
-If you don't want anybody to see it, enter 0 for width and height.
-When someone presses return while the textfield is selected, the button will return EventID $401 and its eventsource, because of the style flag 4, a new one. Read all about this flag at the online help on
I hope I could help you.
| can this bug please be fixed with a next release ??? |
| That's not a bug. It's a change.|
As Beaker wrote some lines before, you must create a button with style flag 4 and this button generates an event when the user presses return while the textfield is created.
| can you please post an example code ??|
as far as i understand i need a textfield AND a button to register a Return key press ???
why is it so complicated ????
W = CreateWindow("Blub",100,100,200,200,Desktop(),1) T = CreateTextField(10,40,70,20,W) B = CreateButton("OK",100,40,40,20,W,4) ; You can hide this or set 0 for width and height if you don't want it to be seen. Repeat Select WaitEvent() Case $803 End Case $401 If EventSource() = B Then Notify "you pressed Return in the textfield!"+Chr(13)+"Or you clicked the Button..."+Chr(13)+"Your Text: "+TextFieldText(T) End Select Forever
why is it so complicated ????
Ask Mark Sibly. But this is the solution to avoid the problem.
| Yeah, the button-trick works just fine.|
You can capture the latest TextField that was used before enter is hit:
W = CreateWindow("Blub",100,100,200,200,Desktop(),1) T1 = CreateTextField(10,40,70,20,W) T2 = CreateTextField(10,65,70,20,W) B = CreateButton("OK",100,40,40,20,W,4) ; You can hide this or set 0 for width and height if you don't want it to be seen. currentTextField = 0 Repeat Select WaitEvent() Case $803 End Case $401 ; As this event is triggered when the text in the textfields changes, ; you can capture the textfield that was used before we hit enter if eventsource() = T1 then currentTextField = T1 if eventsource() = T2 then currentTextField = T2 If EventSource() = B Then Notify "you pressed Return in the textfield!"+Chr(13)+"Or you clicked the Button..."+Chr(13)+"Your Text: "+TextFieldText(currentTextField) end if End Select Forever
And thank you everyone for figuring this out! I had some baaaad time trying to figure this out...