Author Topic: UIKeyBinding  (Read 12278 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
UIKeyBinding
« on: November 22, 2013, 10:31:32 PM »
Overview

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 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.



Pro-Tip

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

http://tasharen.com/ngui/docs/class_u_i_key_binding.html

If you have a question regarding this component or would like me to clarify something, just post a reply here.

CBYum

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UIKeyBinding
« Reply #1 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)
  2.  
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)
  2.  

Ta


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIKeyBinding
« Reply #2 on: January 20, 2014, 07:38:21 AM »
It's already been fixed in 3.0.9. You should update.

Cine

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIKeyBinding
« Reply #3 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIKeyBinding
« Reply #4 on: March 03, 2015, 05:53:15 PM »
Makes sense.

nicloay

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIKeyBinding
« Reply #5 on: March 25, 2015, 03:18:23 AM »
is this possible to adjust event order.
I have following structure
UIRoot
|--- 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: UIKeyBinding
« Reply #6 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.