Support => NGUI 3 Support => Topic started by: Holy Manfred on December 28, 2013, 12:13:41 PM
Title: Getting keyboard input events
Post by: Holy Manfred on December 28, 2013, 12:13:41 PM
I'd like to check for certain keys being pressed using the NGUI event system if this is possible. I have a game object which is handling all kinds of UI stuff. It is set up with
UICamera.genericEventHandler= gameObject;
to receive all events happening. That works well for click, double-click, scroll etc. but I am having problems getting keyboard input. My OnKey function looks like this:
void OnKey(KeyCode key)
{
Debug.Log("OnKeyCode "+ key);
}
and I would expect it to get all kinds of keys pressed on the keyboard. However currently I only get certain inputs like 'UpArrow' 'RightArrow', etc. However I would like to be able to get any key or key combination being pressed so I can react to things like ESCAPE, SHIFT-S, CTRL-P, etc.
Of course I can do this the hacky way with Input.GetKeyDown... but I'd really like to use the NGUI events. I am sure there must be some script or component where I can customize what keys will trigger what events. Using UIKeyBinding is not an option for me because I need to react to a lot of global things happening which might not be related to specific objects in the world. Any suggestions on how to achieve this would be welcome.
Title: Re: Getting keyboard input events
Post by: ArenMook on December 28, 2013, 04:20:16 PM
NGUI doesn't listen to all keys, just specific ones. If you want to listen to all keys, just do it in your own Update() function and check UICamera.selectedObject == gameObject. If not, exit early.