checking ENTER
BlitzPlus Forums/BlitzPlus Programming/checking ENTER
| ||
Hi, Is there a way to check if the user presses enter IF they are inside of a textfield area? I used a check for eventdata but it only works IF the user presses enter before clicking inside a text field. I am making a quiz type game where the user can click inside of a box and type the answer. I have a submit button, but I think its natural to hit enter after the answer is inputed. Anyway here is my code for checking for enter, but as I say it only works if they havent clicked inside the text field. Cls id = WaitEvent (1) Select id Case $101 ;keyDown If EventData() = 28 Then checkAnswer() DebugLog EventData() there is more code of course, but only this is relevant. |
| ||
Check the supplied event_viewer.bb in your \samples\Mak\ folder -- the relevant section is under 'Case $401' (you check for the ASCII code, 13)... |
| ||
Quick example here:; Textfield - ENTER/RETURN win=CreateWindow("TextField + ENTER/RETURN",270,240,234,104,Desktop(),1) tf=CreateTextField(20,20,160,20,win,0) Repeat ev=WaitEvent() ; DebugLog "Event = $"+Right$(Hex$(ev),4) + " "+EventSource() + " "+EventData() If EventSource()=win ActivateGadget win Select ev Case $803 ; close [X] Exit Case $401 ; gadgethit If EventSource()=tf ; TEXTFIELD If EventData()=13 Notify "ENTER/RETURN pressed in textfield" EndIf End Select Forever End The RETURN/ENTER detection only works whilst editing in the textfield. Clicking the window area deactivates the textfield and likewise the RETURN/ENTER key detection. |
| ||
thanks guys, I will give this a shot! |