How can I trigger text entry on number of characters entered

I have a text field, asking for a part number. Entry is terminated by enter/return on keyboard.

I also use a barcode scanner to enter the part number, which works great.
I’d like to avoid having to press enter/return button when using the scanner, which feeds a fixed number of characters.

How can I trigger the event without that extra button push when using scanner?
[import]uid: 6547 topic_id: 21561 reply_id: 321561[/import]

since when you scan it enters all number at one time you can have a setting to turn on a scanner option in the app which would just be a flag that when true it check the textfield for input and when it receives the part number it know to go to next function

edit
or if all number are same number of characters just have a function that checks the length of the string and if the correct number of characters are in it it proceeds to next function use string.len() [import]uid: 7911 topic_id: 21561 reply_id: 85444[/import]

Length is what I want to trigger on so that no extra buttons have to be pushed before or after the scan.

The scanner acts like a keyboard, just no enter key.

I haven’t found the right place to add the check for length.
I’m assuming it has to be in the onMasternum event.

I currently have an additional button event and then do all my checks on that button press. That’s the button press I’m trying to avoid when using scanner, I.e. test that length is 12.

local function onMasternum( event )  
print("In onMasternum")  
 if ( "began" == event.phase ) then  
 masternumField.text=""  
 hidekbButton.alpha=1.0  
 elseif ( "ended" == event.phase ) then  
 masternumField:setTextColor( 51, 51, 122, 255 )  
 native.setKeyboardFocus( nil )  
 hidekbButton.alpha=0  
 elseif ( "submitted" == event.phase ) then  
 masternumField:setTextColor( 51, 51, 122, 255 )  
 native.setKeyboardFocus( nil )  
 hidekbButton.alpha=0  
 end  
end  
  
masternumField = native.newTextField( 50, viewrow+70, 220, 36, onMasternum )  
masternumField.font = native.newFont( native.systemFontBold, 24 )  
masternumField.text = "MasterNumber"  
masternumField:setTextColor( 51, 51, 122, 45 )  
masternumField.inputType = "number"  

Edit: Got it. Added another ‘if’ to check for length. Didn’t think I could do that but seems so :slight_smile:

[import]uid: 6547 topic_id: 21561 reply_id: 85446[/import]

maybe try this

[code]
local function onMasternum( event )
print(“In onMasternum”)
if ( “began” == event.phase ) then
masternumField.text=""
checkInput = timer.performWithDelay( 500, function()
if string.len( masternumField.text ) == 12 then
timer.cancel(checkInput)
event.phase = “submitted”
end end, 0 )

hidekbButton.alpha=1.0
elseif ( “ended” == event.phase ) then
masternumField:setTextColor( 51, 51, 122, 255 )
native.setKeyboardFocus( nil )
hidekbButton.alpha=0
elseif ( “submitted” == event.phase ) then
masternumField:setTextColor( 51, 51, 122, 255 )
native.setKeyboardFocus( nil )
hidekbButton.alpha=0
end
end

masternumField = native.newTextField( 50, viewrow+70, 220, 36, onMasternum )
masternumField.font = native.newFont( native.systemFontBold, 24 )
masternumField.text = “MasterNumber”
masternumField:setTextColor( 51, 51, 122, 45 )
masternumField.inputType = “number”
[/code] [import]uid: 7911 topic_id: 21561 reply_id: 85451[/import]

just saw your edit [import]uid: 7911 topic_id: 21561 reply_id: 85452[/import]

Thanks.
I’ll try that tomorrow. Always nice to have more than one way to do things :slight_smile: [import]uid: 6547 topic_id: 21561 reply_id: 85457[/import]