Type String Event userInput Revision Release 2024.3703 Keywords userInput, phase
A String identifying where in the userInput sequence the event occurred. This can be one of the following values:
"began"
— On devices this is the
"ended"
— This event is sent when the text field/box loses focus, for example when the user touches a different field or when the keyboard is hidden.
"submitted"
— For TextField objects, this event is dispatched when the user presses the "return" key to finish editing. This does not apply to TextBox objects because pressing "return" adds a new line.
"editing"
— This event occurs when the user types or modifies text in the field. During this phase, several other keys are present in the event
table (see the userInput documentation for a complete listing).
local defaultField local function textListener( event ) if ( event.phase == "began" ) then -- User begins editing "defaultField" elseif ( event.phase == "ended" or event.phase == "submitted" ) then -- Output resulting text from "defaultField" print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end -- Create text field defaultField = native.newTextField( 150, 150, 180, 30 ) defaultField:addEventListener( "userInput", textListener )