Page 2 of 2

Re: keyboard focus not work on android TV

Posted: 22 Mar 2016, 01:37
by lomoonmoonbird
Hi
The image had been correctly set like yours , and the the focus was set on the first button when initialized first time ,but i can't control the focus using remote control,but keyboard event did trigger. can you test it on an AndroidTV,please?

Re: keyboard focus not work on android TV

Posted: 22 Mar 2016, 02:46
by jsantos
I think I know what is going on (sorry, we don't have an Android TV here for testing). It seems that we have the keyboard disabled in mobiles, incorrectly I would say.

Please, open the file NoesisUIRenderer.cs (at Assets\Plugins\NoesisGUI\Scripts\Core), at the function ProcessEvent (line 382), remove the lines that set enableKeyboard and enableMouse to false.

From this:
        public void ProcessEvent(UnityEngine.Event ev, bool enableKeyboard, bool enableMouse)
        {
#if !UNITY_STANDALONE && !UNITY_EDITOR
            enableKeyboard = false;
            enableMouse = false;
#endif

            // Process keyboard modifiers
            if (enableKeyboard)
            {
to
        public void ProcessEvent(UnityEngine.Event ev, bool enableKeyboard, bool enableMouse)
        {
            // Process keyboard modifiers
            if (enableKeyboard)
            {
It should work : )

Re: keyboard focus not work on android TV

Posted: 22 Mar 2016, 04:27
by lomoonmoonbird
Hi
I have tried your solution,magic happened, it work perfectly.I’m grateful for your help.Thanks a lot.

But there also remained a small problem, the Enter key on remote control not work, whose keycode is JoystickButton0.

the log

03-22 11:19:33.089: I/Unity(16367): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-22 11:19:33.089: I/Unity(16367): Event:KeyUp Character:\0 Modifiers:None KeyCode:Joystick1Button0
03-22 11:19:33.089: I/Unity(16367):
03-22 11:19:33.089: I/Unity(16367): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-22 11:19:33.089: I/Unity(16367): Layout
03-22 11:19:33.089: I/Unity(16367):
03-22 11:19:33.089: I/Unity(16367): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-22 11:19:33.089: I/Unity(16367): Event:KeyUp Character:\0 Modifiers:None KeyCode:JoystickButton0
03-22 11:19:33.089: I/Unity(16367):
03-22 11:19:33.089: I/Unity(16367): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-22 11:19:33.089: I/Unity(16367): Layout
03-22 11:19:33.089: I/Unity(16367):
03-22 11:19:33.089: I/Unity(16367): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-22 11:19:33.089: I/Unity(16367): Event:KeyDown Character:\0 Modifiers:None KeyCode:Joystick1Button0
03-22 11:19:33.089: I/Unity(16367):
03-22 11:19:33.089: I/Unity(16367): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-22 11:19:33.089: I/Unity(16367): Layout
03-22 11:19:33.089: I/Unity(16367):
03-22 11:19:33.089: I/Unity(16367): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-22 11:19:33.089: I/Unity(16367): Event:KeyDown Character:\0 Modifiers:None KeyCode:JoystickButton0
03-22 11:19:33.089: I/Unity(16367):
03-22 11:19:33.089: I/Unity(16367): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-22 11:19:33.092: I/Unity(16367): Layout
Thanks again,i will be so grateful if you can help me to solve this problem :)

Re: keyboard focus not work on android TV

Posted: 22 Mar 2016, 10:50
by sfernandez
If you are using NoesisGUI 1.2, you can attach a MonoBehavior to the game object next to the NoesisGUIPanel, to inject the input events that your application requires. You can also define different mappings depending on the controller type.

For example:
public abstract class BaseController: MonoBehaviour
{
    NoesisGUIPanel gui;

    void Start()
    {
        gui = GetComponent<NoesisGUIPanel>();
    }

    void OnGUI()
    {
        if (gui != null && UnityEngine.Event.current.type == UnityEngine.EventType.KeyDown)
        {
            ProcessKey(UnityEngine.Event.current.keyCode);
        }
    }

    protected void GenerateNoesisKey(Noesis.Key key)
    {
        gui.KeyDown(key);
    }

    protected abstract void ProcessKey(UnityEngine.KeyCode key);
}
public class GamePadController: BaseController
{
    protected override void ProcessKey(UnityEngine.KeyCode key)
    {
        switch (key)
        {
            case KeyCode.JoystickButton0:
            {
                GenerateNoesisKey(Noesis.Key.Up);
                break;
            }
            case KeyCode.JoystickButton1:
            {
                GenerateNoesisKey(Noesis.Key.Left);
                break;
            }
            case KeyCode.JoystickButton2:
            {
                GenerateNoesisKey(Noesis.Key.Right);
                break;
            }
            case KeyCode.JoystickButton3:
            {
                GenerateNoesisKey(Noesis.Key.Down);
                break;
            }
            // etc.
        }
    }
}
public class RemoteController: BaseController
{
    protected override void ProcessKey(UnityEngine.KeyCode key)
    {
        switch (key)
        {
            case KeyCode.Joystick1Button0:
            {
                GenerateNoesisKey(Noesis.Key.Return);
                break;
            }
            case KeyCode.Joystick1Button1:
            {
                GenerateNoesisKey(Noesis.Key.Escape);
                break;
            }
            // etc.
        }
    }
}

Re: keyboard focus not work on android TV

Posted: 23 Mar 2016, 08:03
by lomoonmoonbird
Hi
Great, I have made it worked with your solution,Thank you Mr save the day.NoesisGUI is a greet plugin,I will dive deeper into NoesisGUI,maybe i will need your help when i meet other ploblems.
Anyway, Thanks very much :)

Re: keyboard focus not work on android TV

Posted: 23 Mar 2016, 17:39
by jsantos
Thanks for the good comments!

By the way, I think we should improve the way we handle key events by supporting Unity Virtual Axes. That way you can configure the mapping for our events: Up, Left, Down, Right, FocusNext, FocusPrev, Action...