Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: huangweicong on September 13, 2012, 08:38:29 PM

Title: Event for Show & Hide Keyboard
Post by: huangweicong on September 13, 2012, 08:38:29 PM
hi, I am new here.

I want to catch the event for showing and hiding keyboard, but I didn't find any API in UIInput.
Now I used a MonoBehaviour to override the OnSelect function which represent event for showing keyboard and new a onSubmit to catch the event for hiding keyboard.

But it didn't work perfectly. When I tapped the close button on the keyboard, I cannot catch the event.

Are there any better solutions?

By the way, how can I set the attribute hideInput to the TouchScreenKeyboard, also, I didnt find any API.

Thanks
Title: Re: Event for Show & Hide Keyboard
Post by: dlewis on September 13, 2012, 10:10:00 PM
NGUI looks for the user to press on a text input box (I don't know the proper name, haven't used it yet) and then it calls the Unity API for opening the keyboard.

Have you seen the code in UIInput.cs at line ~200 to ~250, that deals with opening the keyboard when the input box is pressed and what to do if it's deselected (which may happen when the user dismisses the keyboard)
Title: Re: Event for Show & Hide Keyboard
Post by: huangweicong on September 13, 2012, 10:35:54 PM
Thanks for prompt reply.

Yes, I have seen the codes. And it works well on opening keyboard. But there is a problem when closing keyboard.
When I tap done button to finish tapping, it works well because the script uses the delegate onSubmit in line 291. But when I tap close button to close keyboard, it doesn't work.

I don't know how to catch this event, and does it also use OnSelect function whenever I close the keyboard?

And how can I set the mKeyboard to hideInput? any function I can use?

Thanks
Title: Re: Event for Show & Hide Keyboard
Post by: huangweicong on September 13, 2012, 10:41:22 PM
I have tested the script, it seems like that when I lost focus on the keyboard, it will call OnSelect function, but meanwhile, the keyboard are not necessarily closed.
Title: Re: Event for Show & Hide Keyboard
Post by: ArenMook on September 14, 2012, 03:50:21 AM
I'm a bit confused. How do you close an on-screen keyboard without submitting it? What is the close button you mentioned? Do you know what event is sent out when that happens?
Title: Re: Event for Show & Hide Keyboard
Post by: sluresylta on September 14, 2012, 03:57:57 AM
Maybe he means the back button, as you would find it on Android devices? Tapping that will dismiss the keyboard (on my Samsung Galaxy phone, anyway) without submitting anything to the text field.
Title: Re: Event for Show & Hide Keyboard
Post by: huangweicong on September 14, 2012, 05:35:13 AM
the close button is in the right-bottom of the keyboard, when you tapped it, nothing happened but closed the keyboard
Title: Re: Event for Show & Hide Keyboard
Post by: ArenMook on September 14, 2012, 07:08:24 AM
Bottom-right button for me is the return key.
Title: Re: Event for Show & Hide Keyboard
Post by: ryan on September 14, 2012, 10:50:33 AM
iOS keyboard has a button to close the keyboard that is not triggering a submit in NGUI.  Maybe it's just on iPad, but here's an example, bottom right key:

http://www.maclife.com/files/u12635/reminders_1.png (http://www.maclife.com/files/u12635/reminders_1.png)
Title: Re: Event for Show & Hide Keyboard
Post by: ArenMook on September 14, 2012, 04:33:31 PM
Ah, interesting, thanks for the pic. What event is sent out when it's pressed, do you know?
Title: Re: Event for Show & Hide Keyboard
Post by: triggly_glix on February 12, 2014, 07:58:54 AM
Hmm... i'm still seeing this exact problem - was it ever solved?
thanks...
Title: Re: Event for Show & Hide Keyboard
Post by: ArenMook on February 13, 2014, 03:08:32 AM
Unity's handling of keyboards seems different on Android vs iOS. On Android all methods of closing the keyboard trigger a submit event. NGUI checks keyboard.wasCanceled (which is never true on Android), and does a Submit() if it wasn't cancelled. If it was cancelled, then NGUI simply removes the focus from the input field which results in an OnSelect(false) message being sent.
Title: Re: Event for Show & Hide Keyboard
Post by: kyubuns on May 02, 2014, 06:59:24 AM
I'm using NGUI 2.6.3.

for fix this problem,
Quote
in void Update()
in UIInput.cs

if (mKeyboard.done)

if (mKeyboard.done || !mKeyboard.active)

What do you think?
Title: Re: Event for Show & Hide Keyboard
Post by: ArenMook on May 02, 2014, 09:21:17 AM
So Unity doesn't set 'done' in some cases?
Title: Re: Event for Show & Hide Keyboard
Post by: kyubuns on May 03, 2014, 06:53:16 AM
I tried pushing [hide]button(right-bottom) in iPad keyboard.
then, mKeyboard.done is false and mKeyboard.active is false.

it may be unity's bug.
but, it is in newest Unity(4.3.4f1).
Title: Re: Event for Show & Hide Keyboard
Post by: PoN on May 05, 2014, 02:38:53 AM
i have same bug, if i press Hide keyboard button , then i try to tap on input field for invoke keyboard but nothing happens, that means if i have closed keyboard, i can't invoke(open) keyboard by tap on inputfield, need to reopen (disable/enable) GameObject with UIInput.
Title: Re: Event for Show & Hide Keyboard
Post by: ArenMook on May 05, 2014, 11:21:21 PM
I've added the active check to the current version of NGUI, so you will see it in the next update.
Title: Re: Event for Show & Hide Keyboard
Post by: Daigoro Takeuchi on October 05, 2015, 11:22:06 PM
We are using UIInput script in NGUI 3.9.0 to allow our user to type in our iOS app.
Is there a way to know if the user chose to Hide the keyboard(using the button at the bottom right of the digital keyboard) or chose to press the Done button?
Title: Re: Event for Show & Hide Keyboard
Post by: ArenMook on October 07, 2015, 08:21:45 PM
One should call submit, the other simply close the keyboard. If there is no distinction on iOS, then it would be a question for Unity as there is certainly a distinction on Android.