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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

TouchScreenKeyboard Bug - Status Incorrect

Discussion in 'Android' started by Npicouet, Apr 18, 2020.

  1. Npicouet

    Npicouet

    Joined:
    May 17, 2018
    Posts:
    27
    I'm using a standard InputField setup. When the keyboard opens, touchscreenkeyboard returns its status as visible. When I click off the keyboard to close it (anywhere on the screen that isn't the keyboard), the keyboard closes, and returns that its still visible, and doesn't get unselected. This causes Unity EventSystem to think its still select on the InputField, so you can't click it again until you select another element.

    I was trying workarounds, but the status reported on the touchscreenkeyboard is not accurate, so its hard to work around currently.

    This only happens when clicking off keyboard in empty space. If I use the done or ok buttons, it closes and works fine.

    EDIT: Unity 2019.3.9f1, Android LG G7 ThinQ
     
    Last edited: Apr 18, 2020
  2. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    207
    Also happens in the LTS versions:
    2018.4.21, 2018.4.20, 2018.4.19
    Maybe more, I gave up rolling back one version at a time and went to 2018.4.14 to stop this happening.
    Happens on Nexus 5x, Amazon Fire Hd and a untold amount of other devices going my bug reports from users.

    This is made worse for us as we dont use the event system so there is no way of telling if a user is done with the keyboard, as the state property enum is never "done"
     
    Npicouet likes this.
  3. Daryl_1

    Daryl_1

    Joined:
    Feb 13, 2014
    Posts:
    22
    The same thing also happens when using the TextMeshPro InputField

    Confirmed in LTS: 2018.4.21
     
    Npicouet likes this.
  4. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
    Damn I have this same problem.
    After a lot of debugging.
    I'm getting close to figuring out what is going on.
    When the keyboard is open and you tap out side the keyboard. Unity actually doesn't detect the on screen tab I don't think. But the keyboard does detect it which is why it closes.

    For instance. When you are in the editor in playmode and you click out side the GameView window. The game won't register any of your click events until you click back on the GameView Window.
    I believe the Android device is in this same state when the keyboard is active.

    Still have no fix but sorta understanding the problem in trying to get a fix. If i can just detect that tap then I can do some logic to unselect the inputField.
     
  5. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    207
    Or Unity could fix the regression :(
    I spent ages trying to do loads of workarounds but none worked consistently. e.g detecting focus changes, having a invisible full screen button..
     
  6. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
    I just started reading this huge post on this issue. Not sure if there is a answer in it or not yet.
    https://forum.unity.com/threads/touchscreenkeyboard-and-losing-focus.147095/

    But ya i see exactly whats going on. Even the touchScreenKeyboard.status stays on Visible when tapping off the keyboard.

    Its just like the clicking off screen in the editor. You must click somewhere on Game View first before any UI button is able to be clicked on.

    I came up with an idea that I haven't tried yet. I don't think it will work cause Unity won't detect that first click no matter what. If it does detect the click out side the keyboard then I could figure out if the click is not on the keyboard by doing math as to where the keyboard is at on the screen.

    Edit: I see now that you posted on that thread as well lol.
     
    Last edited: Apr 23, 2020
  7. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
    Actually I just noticed a 2nd problem. God.....
    When you finish hitting ok or done on the keyboard. The inputfield doesn't lose focus correctly unless you click on another UI element first.
    DeactivateInputField doesn't work
    I tried to invoke a click and that doesn't work either strangely.
     
  8. Npicouet

    Npicouet

    Joined:
    May 17, 2018
    Posts:
    27
    I don't remember problems in earlier versions of Unity, this is definitely something they have to fix.
    It's actually a very typical use case for my users and almost everyone has noticed it.
     
  9. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    207
    Yeah its a regression :(
     
  10. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
    I just want to mention also that this issue does not exist for IOS. so its just a android bug.
     
  11. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    207
    Unity just released a new 2018 LTS, still not in the known issues list or fixed :(
     
  12. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
    Notice how the list of fixes is only 6 or something. Like wtf.
    I submited a bug report on web gl issue and with a test project that only shows the bug and it's been 3 months now no fix.
     
    Last edited: May 3, 2020
  13. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    207
    I also have several regression bugs that have reappeared in the 2018.4 LTS, that known issues list is always a lie.
     
  14. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    207
    e.g. Filter Touches When Obscured - Now breaks ALL input on some android devices.
    Found that one out the hard way.. Again another regression in an LTS version.
     
  15. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
    I might as well just use 2019 it seems if LTS leases aren't going to get many updates.
     
  16. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
  17. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    207
    Its not listed as fixed in the LTS on the release notes, but says it is in the issue tracker :(
     
  18. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    That means the currently available version does not have the fix yet, but the future versions will have this fix.
     
  19. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
  20. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    207
    Yeah we are just on 2018.4 so when it said fixed in the issue tracker I assumed it meant it was fixed, not waiting for the fix, it was never mentioned in any 2018.4 release notes as a known issue either so thought unity might have just have missed actually adding it to the release and just rubber stamped the issue tracker as done.
     
  21. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
    i dont think they really keep the known issue list updated all the time it seems.
    Guess we will see. i was hoping for that update today but it seems no lol.
     
  22. topete

    topete

    Joined:
    Nov 27, 2013
    Posts:
    1
    Hey everyone, if you are still having problems with this. Here is what I did for android.
    When the keyboard opens on android the app looses focus. So you can use OnApplicationFocus() to detect when user clicks off the keyboard. Also for some reason when doing this the inputField is like disabled somehow, so I did this
    inputField.enabled = false;
    Timing.CallDelayed(0.1f, () => inputField.enabled = true);
    To make it work again.

    Also in case you are using text mesh pro input field you can use the function

    -inputField.onTouchScreenKeyboardStatusChanged

    You just add a listener and check if the status of the keyboard is "done", this is called when user clicks on "done" button in the keyboard.

    Hope that helps
     
  23. DanOtt

    DanOtt

    Joined:
    Nov 4, 2019
    Posts:
    9
    I used the onTouchScreenKeyboardStatusChanged event but noticed that it seems to work only partially:
    https://answers.unity.com/questions/1778300/tmp-inputfield-does-not-fire-ontouchscreenkeyboard.html

    On iOS it seems like the event is not fired at all (Unity 2019.4.1f11)
     
  24. ant4444

    ant4444

    Joined:
    Jun 7, 2017
    Posts:
    2

    I'm working on 2019.4.13f1

    And it seems we have these problems on TMP_InputField:

    1. The "OnSelect" event is triggered, but when I deselect the same field, and again select it, the "OnSelect" event is not invoked. It is only invoked when we select some other field and then reselect the initial field.

    2. The OnTouchScreenKeyboardStatusChanged event, doesn't get invoked for the status "Visible". but works for others.

    Phone Tested on is Samsung s8, Android version 9
     
    Last edited: Dec 7, 2020
  25. ant4444

    ant4444

    Joined:
    Jun 7, 2017
    Posts:
    2
    on a google keyboard. NOTE: Samsung default keyboard is some other not google.
     
  26. RaventurnPatrick

    RaventurnPatrick

    Joined:
    Aug 9, 2011
    Posts:
    173
    Still encountering the Bug with Unity 2019.4.18f1 on both Android and iOS devices.
    I found a temporary fix that seems to work and cause no adverse effects on mobile?

    Just derive your own class from TMP_InputField and override the OnSelect method as empty to completely disable it
    Code (CSharp):
    1.  
    2. public class InputFieldWithFix : TMP_InputField
    3. {
    4.     public override void OnSelect(BaseEventData eventData)
    5.     {
    6.       // we disallow selecting the input field as this causes bugs on mobile
    7.       //base.OnSelect(eventData);
    8.     }
    9. }
    10.  
     
  27. madfu

    madfu

    Joined:
    Aug 9, 2018
    Posts:
    19
    since i also experienced this problem on Unity 2019.4.17f1, i offer my own $0.02 fix here : Keyboard height
     
  28. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,628
    This is definitely fixed in 2018.4
     
  29. v_bashiri

    v_bashiri

    Joined:
    Jul 22, 2018
    Posts:
    1
    I still have this problem in 2020.3.5

    My work around was to check _myTMPInputField.isFocused in update and call a function in addition to set a flag so it doesn't call multiple time while input field is focused.


    Yet, there is another problem. Here I don't have keyboard height and checking for TouchScreenKeyboard.visible only works first time. After opening and closing keyboard it seems TouchScreenKeyboard.visible become true before keyboard opens, And height of keyboard will be 0.

    Any idea what can I do for that?
     
    Last edited: May 10, 2021
  30. madfu

    madfu

    Joined:
    Aug 9, 2018
    Posts:
    19
    in my experience the keyboard visibility flag is wholly inaccurate and has been for some time.

    there's another thread on this forum that discusses a fix that detects and calculates the screen height of the native keyboard in Android (and includes a code snippet of some code i use). however, my sense from the feedback received on that thread is that the code present there is difficult to make useful without some intimate knowledge about how Android and Unity interact. it's not the whole solution. your-mileage-may-vary, but it might give you some ideas.
     
    Last edited: May 10, 2021