lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: keyboard focus not work on android TV

22 Mar 2016, 01:37

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?
 
User avatar
jsantos
Site Admin
Posts: 2900
Joined: 20 Jan 2012, 17:18
Contact:

Re: keyboard focus not work on android TV

22 Mar 2016, 02:46

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 : )
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: keyboard focus not work on android TV

22 Mar 2016, 04:27

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 :)
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: keyboard focus not work on android TV

22 Mar 2016, 10:50

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.
        }
    }
}
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: keyboard focus not work on android TV

23 Mar 2016, 08:03

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 :)
 
User avatar
jsantos
Site Admin
Posts: 2900
Joined: 20 Jan 2012, 17:18
Contact:

Re: keyboard focus not work on android TV

23 Mar 2016, 17:39

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

Who is online

Users browsing this forum: Google [Bot] and 1 guest