Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question Unity - iPad mini - BT UPC Scanner - no work...

Discussion in 'Editor & General Support' started by daveMennenoh, Mar 26, 2023.

  1. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    86
    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: https://docs.unity3d.com/ScriptReference/Input-inputString.html 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?
     
  2. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    86
    Code (CSharp):
    1. public class InputTest : MonoBehaviour
    2. {
    3.     public TextMeshProUGUI final;
    4.     public TMP_InputField barcodeField;
    5.  
    6.     public void Start()
    7.     {
    8.         barcodeField.Select();
    9.         barcodeField.ActivateInputField();
    10.     }
    11.    
    12.     private void Update()
    13.     {
    14.         ReadBarcodeInput();
    15.     }
    16.    
    17.     private void ReadBarcodeInput()
    18.     {
    19.         foreach (char c in Input.inputString)
    20.         {
    21.             if ((c == "\n"[0]) || (c == "\r"[0]))
    22.             {
    23.                 final.text = barcodeField.text;
    24.                 barcodeField.text = "";
    25.             }
    26.             else
    27.             {
    28.                 barcodeField.text += c;
    29.             }
    30.         }
    31.     }  
    32. }
    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???
     
  3. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    86
    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.
     
  4. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    86
    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.
     
  5. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    86
    BTW ChatGPT, which is 100% regarded, suggests using OnGUI to listen to the keyboard events. LOL