Search Unity

How to hook up TMPro input field to fake keyboard?

Discussion in 'UGUI & TextMesh Pro' started by JoeStrout, Sep 22, 2020.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'm making a UI in VR that uses a "fake" keyboard — a bunch of 3D objects that the user can poke, each one sending a character or control code. I'd like to make this work properly with a TMPro input field.

    I have it mostly working by getting the field's selectionAnchorPosition, selectionFocusPosition, and text, manipulating these appropriately, and stuffing them back into the field. But the problem is, I can't get the blinking cursor (much less an extended selection) to show.

    It looks as though the input field is seeing that there is no "real" keyboard, and so refusing to accept the focus (or maybe just refusing to draw the cursor/selection).

    How can I work around this? Is there some way to turn my virtual keyboard into a more standard-looking keyboard the UI system (including TMP_InputField) will recognize as a keyboard? Or some way to tell the field not to worry about it, and display normal caret/selection behavior regardless?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    I know that some users have implemented their own virtual keyboard but not sure how they implemented it nor have I even looked into it.

    Sending key events to the input field should work thus making it think they are coming from some keyboard.

    With regards to the caret and selection, that should work by setting those anchor, selection positions. D

    Do you have anything you can share with me via PM / private link where I could download some project prototype to look at?
     
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Yeah, the caret and selection do not show even though I am setting them, and calling Select() on the field — I suspect it is not actually getting the focus, probably because the event system thinks no keyboard is available.

    Sending key events sounds better than what I'm currently doing to fake the typing. Can you sketch out in a little more detail how I would do that?

    I will make a simple project and share with you by PM later today.