How to use KEYCODE_DPAD_CENTER key code in Unity

1.4k Views Asked by At

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!

1

There are 1 best solutions below

0
Salbrox On

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);
            }
        }
    }
}