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

keyboard focus not work on android TV

15 Mar 2016, 05:36

I used NoesisGUI 1.1, and compiled the sample of Styles under Assets/NoesisGUI/Samples/Styles to android platform in Unity (File/Build Setting/,select android and build), after installed on Android TV, the interface showed, but the button focus not work both with game handler and remote control.it worked on PC, when using keyboard such as left,right and other control.anyone can tell me the truth? or noesisgui not support android tv yet? :cry: :cry: :cry: :cry:
 
User avatar
jsantos
Site Admin
Posts: 3925
Joined: 20 Jan 2012, 17:18
Contact:

Re: keyboard focus not work on android TV

15 Mar 2016, 13:17

Hi,

We didn't try android TV but if this is correct, at least the arrow buttons should work because they map to KeyCode.UpArrow, KeyCode.DownArrow, KeyCode.LeftArrow and KeyCode.DownArrow. Could you verify that these events are working?

For the focus event we need to map it to the TAB event. Could you please dump the event that Unity is generating when you use the button focus? (just log the UnityEngine.Event.current in NoesisGUIPanel::OnGUI() method)

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

Re: keyboard focus not work on android TV

16 Mar 2016, 12:32

Hi
Here is my test code below:

button.xaml:
<Grid
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 mc:Ignorable="d">

  
  <Grid>
    <StackPanel  Background="Ivory" Orientation="Horizontal">
      <Canvas Width="10"/>
      <Button x:Name="t1" Width="100"  Height="30" FocusVisualStyle="{DynamicResource MyFocusVisual}">
        Focus 1
      </Button>
      <Canvas Width="100"/>
      <Button x:Name="t2" Width="100" Height="30" FocusVisualStyle="{DynamicResource MyFocusVisual}">
        Focus 2
      </Button>
    </StackPanel>
  </Grid>
</Grid>

Dictionary1.xaml:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:WpfApplication3">
    <Style x:Key="MyFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle Margin="-8" StrokeThickness="1" Stroke="Red"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
Button.cs:
using UnityEngine;
using System.Collections;
using System;
public class Button : MonoBehaviour {

    int count = 0;
    int countGUI = 0;

    NoesisGUIPanel noesisguipanel;
    Noesis.Grid _gridroot;
    Noesis.Button _button1;
	// Use this for initialization
	void Start () {


        noesisguipanel = GetComponent<NoesisGUIPanel>();

        _gridroot = noesisguipanel.GetRoot<Noesis.Grid>();

        _button1 = _gridroot.FindName<Noesis.Button>("t1");


        _button1.Focus();

        _button1.Click += _button1_click;

    }
	
    public void _button1_click(object sender, Noesis.RoutedEventArgs e)
    {

        for(int i =0; i< Input.GetJoystickNames().Length; i++)
        {
            Debug.Log("Key:" + i + "Name:" + Input.GetJoystickNames()[i]);
        }
    }

	// Update is called once per frame
	void Update () {

    }

    void OnGUI()
    {
        Debug.Log("the current focus:" + UnityEngine.Event.current.keyCode.ToString());

    }
}

When i run this test in Unity,i pressed the keyboard in the order of up,left,down and right,and unity logged this out:
log on Unity Console:
the current focus:None
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)

the current focus:UpArrow
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)

the current focus:LeftArrow
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)

the current focus:DownArrow
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)

the current focus:RightArrow
UnityEngine.Debug:Log(Object)
Button:OnGUI() (at Assets/ButtonTest/Button.cs:45)
When i compiled this in Android package and installed on TV,with remote control button pressed,the log was printed on eclipse:

log on eclipse:
03-16 17:33:18.220: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.220: I/Unity(20596): The current focus : JoystickButton3
03-16 17:33:18.220: I/Unity(20596):
03-16 17:33:18.220: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.230: E/InputDispatcher(1691): keyCode 96,scanCode 304
03-16 17:33:18.230: D/AliTVASR(2859): AliTVASR(TVSensorDevice)->(1)->TVSensorDevice, received DKeyEvent:mData:mSize=1, mKeyCodes[0]=96, mActions[0]=0
03-16 17:33:18.230: D/WindowManager(1691): keycode is 96 , and POWER is 26
03-16 17:33:18.230: D/PowerManagerService(1691): AliScreenSaver:MSG_USER_ACTIVITY_TIMEOUT is sent.... delta = 863992999
03-16 17:33:18.230: D/PowerManagerService(1691): AliScreenSaver:MSG_ALI_SCREEN_SAVER_TIMEOUT is sent.... delta = 431999999
03-16 17:33:18.240: I/Unity(20596): The current focus : JoystickButton3
03-16 17:33:18.240: I/Unity(20596):
03-16 17:33:18.240: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.240: I/Unity(20596): The current focus : JoystickButton3
03-16 17:33:18.240: I/Unity(20596):
03-16 17:33:18.240: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.250: I/Unity(20596): The current focus : Joystick1Button0
03-16 17:33:18.400: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.410: E/InputDispatcher(1691): keyCode 100,scanCode 308
03-16 17:33:18.410: D/WindowManager(1691): keycode is 100 , and POWER is 26
03-16 17:33:18.410: D/AliTVASR(2859): AliTVASR(TVSensorDevice)->(1)->TVSensorDevice, received DKeyEvent:mData:mSize=1, mKeyCodes[0]=100, mActions[0]=0
03-16 17:33:18.420: E/InputDispatcher(1691): keyCode 96,scanCode 304
03-16 17:33:18.420: D/WindowManager(1691): keycode is 96 , and POWER is 26
03-16 17:33:18.420: D/AliTVASR(2859): AliTVASR(TVSensorDevice)->(1)->TVSensorDevice, received DKeyEvent:mData:mSize=1, mKeyCodes[0]=96, mActions[0]=1
03-16 17:33:18.420: I/Unity(20596): The current focus : JoystickButton0
03-16 17:33:18.420: I/Unity(20596):
03-16 17:33:18.420: I/Unity(20596): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-16 17:33:18.420: I/Unity(20596): The current focus : JoystickButton0

Can you point out what is going on? am i missing anything? Thanks in advance :)
 
User avatar
jsantos
Site Admin
Posts: 3925
Joined: 20 Jan 2012, 17:18
Contact:

Re: keyboard focus not work on android TV

17 Mar 2016, 08:39

The problem is that the events being generated by AndroidTV (JoystickButton0, JoystickButton1,...) are ignored by NoesisGUI. In v1.2 we added public methods to inject events manually. For example, in NoesisGUIPanel.cs you can find
    #region Keyboard input events
    /// <summary>
    /// Notifies Renderer that a key was pressed.
    /// </summary>
    /// <param name="key">Key identifier.</param>
    public void KeyDown(Noesis.Key key)
    {
        if (_uiRenderer != null)
        {
            _uiRenderer.KeyDown(key);
        }
    }

    /// <summary>
    /// Notifies Renderer that a key was released.
    /// </summary>
    /// <param name="key">Key identifier.</param>
    public void KeyUp(Noesis.Key key)
    {
        if (_uiRenderer != null)
        {
            _uiRenderer.KeyUp(key);
        }
    }
So, you have to inject manually the events that you need. I recommend you switching to v1.2, but if you want to stay in v1.1 then you have to modify the code to expose those functions. It should be easy. Just tell me if you find problems.

Thinking more about this, I don't know if we should add a entry in our panel to visually configure events redirections.
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: keyboard focus not work on android TV

17 Mar 2016, 08:51

Hi
Thanks for replying,
Can you write some example codes or a complete demo is better,because i am newbie to NoesisGUI, I stuck into this problem for weeks, god help me~ i will be much grateful.
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: keyboard focus not work on android TV

17 Mar 2016, 11:06

Hi
Here is the thing,the log above that showed (JoystickButton0, JoystickButton1,..) is came from game handler, i tried remote control just now,and the log showed are below:
03-17 17:56:44.683: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:44.683: I/Unity(5939): The current focus : RightArrow
03-17 17:56:44.683: I/Unity(5939):
03-17 17:56:44.683: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:44.703: I/Unity(5939): The current focus : RightArrow
03-17 17:56:44.703: I/Unity(5939):
03-17 17:56:44.703: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:44.703: I/Unity(5939): The current focus : RightArrow
03-17 17:56:44.703: I/Unity(5939):
03-17 17:56:44.703: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:44.723: I/Unity(5939): The current focus : RightArrow
03-17 17:56:44.723: I/Unity(5939):
03-17 17:56:44.723: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:44.723: I/Unity(5939): The current focus : RightArrow
03-17 17:56:44.723: I/Unity(5939):
03-17 17:56:44.723: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:44.743: I/Unity(5939): The current focus : RightArrow
03-17 17:56:44.743: I/Unity(5939):
03-17 17:56:44.743: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:44.743: I/Unity(5939): The current focus : RightArrow
03-17 17:56:34.303: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:34.303: I/Unity(5939): The current focus : LeftArrow
03-17 17:56:34.303: I/Unity(5939):
03-17 17:56:34.303: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:34.323: I/Unity(5939): The current focus : LeftArrow
03-17 17:56:34.323: I/Unity(5939):
03-17 17:56:34.323: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:34.323: I/Unity(5939): The current focus : LeftArrow
03-17 17:56:34.323: I/Unity(5939):
03-17 17:56:34.323: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:34.343: I/Unity(5939): The current focus : LeftArrow
03-17 17:56:34.343: I/Unity(5939):
03-17 17:56:34.343: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:34.343: I/Unity(5939): The current focus : LeftArrow
03-17 17:56:34.343: I/Unity(5939):
03-17 17:56:34.343: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:34.363: I/Unity(5939): The current focus : LeftArrow
03-17 17:56:34.363: I/Unity(5939):
03-17 17:56:34.363: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:34.363: I/Unity(5939): The current focus : LeftArrow
03-17 17:56:34.363: I/Unity(5939):
03-17 17:56:34.363: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:34.383: I/Unity(5939): The current focus : LeftArrow
03-17 17:56:34.383: I/Unity(5939):
03-17 17:56:35.723: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:35.724: I/Unity(5939): The current focus : DownArrow
03-17 17:56:35.724: I/Unity(5939):
03-17 17:56:35.724: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:35.727: I/Unity(5939): The current focus : DownArrow
03-17 17:56:35.727: I/Unity(5939):
03-17 17:56:35.727: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:35.727: I/Unity(5939): The current focus : DownArrow
03-17 17:56:35.727: I/Unity(5939):
03-17 17:56:35.727: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:35.743: I/Unity(5939): The current focus : DownArrow
03-17 17:56:35.743: I/Unity(5939):
03-17 17:56:35.743: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:35.744: I/Unity(5939): The current focus : DownArrow
03-17 17:56:35.744: I/Unity(5939):
03-17 17:56:35.744: I/Unity(5939): (Filename: ./artifacts/AndroidManagedGenerated/UnityEngineDebug.cpp Line: 56)
03-17 17:56:35.763: I/Unity(5939): The current focus : DownArrow
The log "The current focus: DownArrow" and the other three keys match with KeyCode in KeyCode enum: UpArrow = 273,
DownArrow = 274,
RightArrow = 275,
LeftArrow = 276,

but on the screen, the focus never move.What is this problem,can you explain how,thanks very much :)
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: keyboard focus not work on android TV

18 Mar 2016, 09:44

Hi,
I also tried Unity5.3 and NoesisGUI 1.2 , and compiled this Game Menu demo https://github.com/Noesis/Tutorials/tree/master/Samples on Android Platform,they worked fine on PC,but focus on android TV still not work with remote control.
Please help me with this problem :)
 
User avatar
jsantos
Site Admin
Posts: 3925
Joined: 20 Jan 2012, 17:18
Contact:

Re: keyboard focus not work on android TV

18 Mar 2016, 15:36

I am testing the Game Menu demo right now. If the remote control is sending UpArrow and DownArrow it should work. So, it must be sending a different code. Please, do the following modificacion to the OnGUI() function in NoesisGUIPanel.cs (please, test with the 1.2 version we have sent you).
void OnGUI()
{
    if (_uiRenderer != null)
    {
        _uiRenderer.ProcessEvent(UnityEngine.Event.current, _enableKeyboard, _enableMouse);
        UnityEngine.Debug.Log(UnityEngine.Event.current);
    }
}
Just launch the demo in AndroidTV, hit the keys and paste here the log.

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

Re: keyboard focus not work on android TV

21 Mar 2016, 07:24

Hi
Sorry for late, I have tried Unity5.3.4 and NoesisGUI 1.2.5, I printed both log on AndroidTV and PC.

On Android TV
03-21 14:19:54.675: I/Unity(24939): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-21 14:19:54.695: D/AliTVASR(3447): AliTVASR(TVSensorDevice)->(1)->TVSensorDevice, received DKeyEvent:mData:mSize=1, mKeyCodes[0]=22, mActions[0]=1

03-21 14:19:54.743: I/Unity(24939): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-21 14:19:54.743: I/Unity(24939): Event:KeyUp Character:\0 Modifiers:None KeyCode:RightArrow

03-21 14:19:54.780: I/Unity(24939): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-21 14:19:54.791: D/AliTVASR(3447): AliTVASR(TVSensorDevice)->(1)->TVSensorDevice, received DKeyEvent:mData:mSize=1, mKeyCodes[0]=22, mActions[0]=0

03-21 14:19:55.928: I/Unity(24939): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-21 14:19:55.929: I/Unity(24939): Event:KeyDown Character:\0 Modifiers:None KeyCode:LeftArrow

03-21 14:19:57.380: I/Unity(24939): (Filename: ./artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
03-21 14:19:57.380: I/Unity(24939): Event:KeyDown Character:\0 Modifiers:None KeyCode:UpArrow
On PC
Event:KeyDown Character:\0 Modifiers:FunctionKey KeyCode:DownArrow
UnityEngine.Debug:Log(Object)
NoesisGUIPanel:OnGUI() (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:457)

Event:KeyUp Character:\0 Modifiers:FunctionKey KeyCode:LeftArrow
UnityEngine.Debug:Log(Object)
NoesisGUIPanel:OnGUI() (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:457)

Event:KeyUp Character:\0 Modifiers:FunctionKey KeyCode:DownArrow
UnityEngine.Debug:Log(Object)
NoesisGUIPanel:OnGUI() (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:457)

Event:KeyDown Character:\0 Modifiers:FunctionKey KeyCode:LeftArrow
UnityEngine.Debug:Log(Object)
NoesisGUIPanel:OnGUI() (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:457)

Event:KeyUp Character:\0 Modifiers:FunctionKey KeyCode:RightArrow
UnityEngine.Debug:Log(Object)
NoesisGUIPanel:OnGUI() (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:457)
It seems that Modifiers on Android TV is None,is that problem?,if so , how to solve it ?
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: keyboard focus not work on android TV

21 Mar 2016, 22:18

Hi,

To move the focus with the arrow keys, modifiers are not important.

My guess is that focus is not correctly set to the first button when MenuDemo is started.
Could you please verify that the "START GAME" button is selected like in the following image?
MenuDemo-start.png
MenuDemo-start.png (278.12 KiB) Viewed 3551 times
I tried the demo on my Android phone and it shows as expected. I can't imagine what is happening with the AndroidTV.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 43 guests