0

I am porting a Unity app to Vuzix M300 Android headset and the select button on top of the device does not work within my Unity app. According to the Vuzix dev support page it uses the key code KEYCODE_DPAD_CENTER which it appears Unity does not see. Is there any way around this as we need to get that button working in our app.

I have also tried KeyCode.JoystickButton0, KeyCode.Return, KeyCode.Enter, KeyCode.Menu, Input.GetButtonDown("Fire1"), KeyCode.Space...

Any help on this would be massively appreciated!

Salbrox
  • 143
  • 1
  • 15
  • Unfortunately Unity docu has no overview map with available keycodes an their according int value... The `KEYCODE_DPAD_CENTER` at least in Android maps to `23` so maybe if you find out which Unity KeyCode Maps to `23` you might be able to use that. – derHugo Jan 28 '19 at 16:56
  • You could print all enum values of `KeyCode` by [iterating over the enum](https://stackoverflow.com/a/482741/7111561) – derHugo Jan 28 '19 at 16:58
  • it's not a language I would know ^^ but it seems that [those poeple](https://blog.csdn.net/cordova/article/details/51036547) somehow managed to map the `KEYCODE_DPAD_CENTER` to a custom (so far unset) `KeyCode 10` like `KeyCode DPAD_CENTER = (KeyCode)10;` maybe you have to try and error a bit until you get the correct value but you could try to access the code using [event.keyCode](https://docs.unity3d.com/ScriptReference/Event-keyCode.html) directly – derHugo Jan 29 '19 at 06:06
  • (I made the enum check and there is no KeyCode with value `10` nor `23` in Unity so maybe you can check both) – derHugo Jan 29 '19 at 06:17
  • @derHugo thank you very much. I figured it out through the Chinese link you provided. – Salbrox Jan 29 '19 at 09:17

1 Answers1

0

Thanks to the link provided by derHugo this is the solution I came up with:

public class VuzixSelectButton : MonoBehaviour
{  
    KeyCode DPAD_CENTER = (KeyCode)10;

    void Update ()
    {
        VuzixSelect();   
    }

    /// <summary>
    /// Detects Vuzix M300 select button presses
    /// </summary>
    private void VuzixSelect()
    {
        if (SystemInfo.deviceModel.ToLower().Contains("vuzix"))
        {
            if (Input.GetKeyDown(DPAD_CENTER))
            {
                var es = EventSystem.current;
                GameObject obj = es.currentSelectedGameObject;
                ExecuteEvents.Execute(obj, new PointerEventData(EventSystem.current), ExecuteEvents.pointerClickHandler);
            }
        }
    }
}
Salbrox
  • 143
  • 1
  • 15