Search Unity

How do you get the instance of the mobile keyboard when it is invoked by an InputField

Discussion in 'UGUI & TextMesh Pro' started by DanSuperNC2, Jan 29, 2016.

  1. DanSuperNC2

    DanSuperNC2

    Joined:
    Sep 29, 2015
    Posts:
    2
    I'm trying to make my UI respond to the appearance of the mobile keyboard by scrolling up to match the area covered by the the mobile keyboard when it is invoked by touching inside of of the InputField.

    My plan was to make a manager that monitors the behavior of the TouchScreenKeyboard and fires off events that different views can respond to, however I cannot seem to find any way to get a reference to the TouchScreenKeyboard instance if you do not invoke the keyboard yourself with TouchScreenKeyboard.Open.
    Nor does there seem to be a way of preventing the InputField from invoking the TouchScreenKeyboard so my own manager can do so instead.

    This seems like a major oversight since the documentation for "TouchScreenKeyboard" says "Because the appearance of the keyboard has the potential to obscure portions of your user interface, it is up to you to make sure that parts of your user interface are not obscured when the keyboard is being displayed."

    Is anyone aware of a method that allows you to get access to the TouchScreenKeyboard instance when it is invoked by an input field that I seem to be missing?
     
  2. miladloveboth

    miladloveboth

    Joined:
    Dec 27, 2015
    Posts:
    2
  3. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    72
    I am having the same issue. Does anyone know how to get the instance?
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I did a quick lookup and it seems that there is a protected member for the TouchScreenKeyboard in the InputField class.
     
  5. FeistyRodent

    FeistyRodent

    Joined:
    Aug 12, 2017
    Posts:
    2
    It looks like TouchScreenKeyboard.Open() returns the instance if it is already open.

    Example:
    if(TouchScreenKeyboard.visible)
    var keyboardInstance = TouchScreenKeyboard.Open(String.Empty);​
     
    Last edited: Jan 23, 2020
  6. Jose_Gallardo

    Jose_Gallardo

    Joined:
    Jul 29, 2010
    Posts:
    42
    Great solution, works great! thanks.