Hi all,
thing is the scanner works fine in any other app I try, like excel or notes. UPC is ‘typed’ (HID device) into wherever the cursor is. However in Unity it either doesn’t work at all, or I get missing digits. I’ve tried every which way I know.
What I’m currently doing is basically right from here: Unity - Scripting API: Input.inputString Reading the inputString directly from the Input system. Works without fail in Windows but either not at all, or just intermittently on the mini.
So right now I just built a test with just a TMP Input field and no code at all. Just trying to get the scanner to type into the field. And still I get nothing or missing chars’. Switch to Notes app and it’s perfect. So it’s Unity - but just on the iPad mini because same code works in Win. And Scanner works on the mini in other apps. Really at a loss. Bug?
public class InputTest : MonoBehaviour
{
public TextMeshProUGUI final;
public TMP_InputField barcodeField;
public void Start()
{
barcodeField.Select();
barcodeField.ActivateInputField();
}
private void Update()
{
ReadBarcodeInput();
}
private void ReadBarcodeInput()
{
foreach (char c in Input.inputString)
{
if ((c == "\n"[0]) || (c == "\r"[0]))
{
final.text = barcodeField.text;
barcodeField.text = "";
}
else
{
barcodeField.text += c;
}
}
}
}
So this is the code I’m testing with right now. On Windows, using an Input field, I get double characters when typing, and two UPC codes when scanning. As I would expect - since I’m appending into an input field, not a text field.
On the iPad mini however, it’s totally different. If I disable the soft keyboard, in the input field options, then when I scan I get an incomplete barcode - but I also get the \r which clears the field and sets final.text to the scanned code. When I don’t disable the soft keyboard I get the full UPC, consistently! Perfect! However the code detects no \r or \n and I only get one set of numbers - I don’t get two like on Windows.
Anyone make sense of this???
One more thing - on Windows I can just use an OnSubmit listener on an input field and the scanning works great. Doesn’t work on the mini which is why I went to grabbing inputString directly.
Just tried a BT keyboard. Inputs into the field, but pressing Enter does nothing. ie the code looking at Input.inputString does not see \r or \n when Enter is pressed.
BTW ChatGPT, which is 100% regarded, suggests using OnGUI to listen to the keyboard events. LOL