Author Topic: Event for Show & Hide Keyboard  (Read 16041 times)

huangweicong

  • Guest
Event for Show & Hide Keyboard
« 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

dlewis

  • Guest
Re: Event for Show & Hide Keyboard
« Reply #1 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)

huangweicong

  • Guest
Re: Event for Show & Hide Keyboard
« Reply #2 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

huangweicong

  • Guest
Re: Event for Show & Hide Keyboard
« Reply #3 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event for Show & Hide Keyboard
« Reply #4 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?

sluresylta

  • Guest
Re: Event for Show & Hide Keyboard
« Reply #5 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.

huangweicong

  • Guest
Re: Event for Show & Hide Keyboard
« Reply #6 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event for Show & Hide Keyboard
« Reply #7 on: September 14, 2012, 07:08:24 AM »
Bottom-right button for me is the return key.

ryan

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 90
    • View Profile
Re: Event for Show & Hide Keyboard
« Reply #8 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
« Last Edit: September 14, 2012, 10:53:14 AM by ryan »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event for Show & Hide Keyboard
« Reply #9 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?

triggly_glix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Event for Show & Hide Keyboard
« Reply #10 on: February 12, 2014, 07:58:54 AM »
Hmm... i'm still seeing this exact problem - was it ever solved?
thanks...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event for Show & Hide Keyboard
« Reply #11 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.

kyubuns

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Event for Show & Hide Keyboard
« Reply #12 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event for Show & Hide Keyboard
« Reply #13 on: May 02, 2014, 09:21:17 AM »
So Unity doesn't set 'done' in some cases?

kyubuns

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Event for Show & Hide Keyboard
« Reply #14 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).