Tasharen Entertainment Forum

Support => NGUI 3 Documentation => Topic started by: ArenMook on November 22, 2013, 10:31:32 PM

Title: UIKeyBinding
Post by: ArenMook on November 22, 2013, 10:31:32 PM

UIKeyBinding lets you make specific key events, such as hitting '1' act as if you were pressing on the object that the key binding was attached to (such as a spell button on your hot bar).

It can also be used to select an input field (http://www.tasharen.com/forum/index.php?topic=6752) in order to start typing (think hitting 'Enter' to start chatting).


Have you ever wished that you could easily open up the player's inventory by pressing the "I" button without having to write code? Well, you can! Just add a Key Binding script to it, and the Key Code to be "I".

How about casting a spell from the hot bar by pressing '1', '2', '3', and so on? Add Key Binding scripts to those buttons as well with the appropriate Key Code keys.

How about activating the chat window's input when pressing 'Enter'? Add a Key Binding script to your chat window's input, set the Key Code to be Return and the Action to be Select.

You can customize this further by setting a Modifier key option in case you wanted something like CTRL+1 activating an ability on the secondary hot bar.



Place key binding scripts on all of your hot bar and menu items. This way you will be activate them by both clicking on them as well as using the hot keys. Even the Main Menu can be brought up by triggering the Escape key binding in the same fashion.

Class Documentation


If you have a question regarding this component or would like me to clarify something, just post a reply here.
Title: Re: UIKeyBinding
Post by: CBYum on January 20, 2014, 07:36:04 AM
I used this to make our mobile app work with the physical back button on Android (escape). When I use this I get an error on the UIButtonColor:OnPress fn. I believe that the UICamera.currentTouch is null and so not handled - which soulds reasonable as I didn't touch the screen.

  1.                 else if (UICamera.currentTouch.current == gameObject && UICamera.currentScheme == UICamera.ControlScheme.Controller)
I've tweaked it with a null check and this seems to work fine now. Is this a good/necessary fix?!!
  1.                                 else if (UICamera.currentTouch!=null && UICamera.currentTouch.current == gameObject && UICamera.currentScheme == UICamera.ControlScheme.Controller)


Title: Re: UIKeyBinding
Post by: ArenMook on January 20, 2014, 07:38:21 AM
It's already been fixed in 3.0.9. You should update.
Title: Re: UIKeyBinding
Post by: Cine on March 03, 2015, 05:21:16 AM
None does not actually mean "None", it means "Any"...

I added the following code in
  1. IsModifierActive
for an option that actually means None:

  1.            if (modifier == Modifier.NoneAllowed)
  2.               return
  3.                  !(Input.GetKey(KeyCode.LeftAlt) ||
  4.                    Input.GetKey(KeyCode.RightAlt) ||
  5.                    Input.GetKey(KeyCode.LeftControl) ||
  6.                    Input.GetKey(KeyCode.RightControl) ||
  7.                    Input.GetKey(KeyCode.LeftShift) ||
  8.                    Input.GetKey(KeyCode.RightShift));

and NoneAllowed in Modifier
Title: Re: UIKeyBinding
Post by: ArenMook on March 03, 2015, 05:53:15 PM
Makes sense.
Title: Re: UIKeyBinding
Post by: nicloay on March 25, 2015, 03:18:23 AM
is this possible to adjust event order.
I have following structure
|--- FullScreenWidget (UIKeyBinding)
|--- DialoguePanel (UIPanel)
|----|----FullScreenWidget (UIKeyBinding)

fullscreenWidget listen Escape button, Dialogue panel sometime become active and on escape it's just close Dialogue panel
Root FullScreenWidget on escape close application.

How it works right now - both UIKeyBinding fired and both event executed, but i need just on with higher depth
Title: Re: UIKeyBinding
Post by: ArenMook on March 25, 2015, 12:22:31 PM
No, you would need to make sure that only one UIKeyBinding is active with the same keybinding at a time.