1

I am trying to get the touchpad of the Vizux M400 to work in Unity. The Vuzix runs on Android and I know that for example a touchpad swipe forward is handled with the android keycode KEYCODE_DPAD_RIGHT (22).

How do I map this keycode now to a keycode in Unity, so that I have access to it? I heard that I might need to create a plugin for that, but I have no idea where to start creating such a plugin. (Side info: Tapping on the touchscreen is received as Mouse0 in Unity, but tapping with 2 fingers is not recognized. So I guess these are not mapped on default)

Any help is appreciated, thank you already!

made3
  • 89
  • 1
  • 5

2 Answers2

1

I don't have the device, so it is difficult for me to test. Generally, you can check the KeyCode of any recognizable device using the following.

// Put this in Update OR OnGUI
if (Input.anyKeyDown)
{
    Event e = Event.current;
    if (e.isKey)
    {
        Debug.Log(e.keycode.ToString())
    }
}

After finding the keycode, use the following code for checking the state:

KeyCode KEYCODE_DPAD_RIGHT = (KeyCode)(<insert your found keycode>)
if (SystemInfo.deviceModel.ToLower().Contains("vuzix"))
{
    if (Input.GetKeyDown(KEYCODE_DPAD_RIGHT))
    {
        // Do anything
    }
}

Edit 1

I believe you can get this to work by explicitly telling Unity to check the different KeyCodes:

        for (int i = 0; i < 1000; i++)
        {
            try
            {
                if (Input.GetKeyDown((KeyCode)i))
                {
                    j++;
                    dText.text = j +" with: "+ i.ToString();
                    Debug.Log("Working");
                    break;
                }
            }
            catch
            {
            }
        }

Edit 2

Run this code in Update and spam clicking your buttons and swiping/touching actions. You may get a prompt that shows that the action is recognized, and you may confirm that the actions are actually mapped by default to some of the keycodes.

made3
  • 89
  • 1
  • 5
Timmy Chan
  • 933
  • 7
  • 15
  • Thank you for your answer. I already did what you suggested. The device has 3 physical buttons and a touchpad which can recognize 3 fingers. I get the KeyCode of the 3 physical buttons (Even different KeyCodes for holding the button or just pressing) and for a touchpad tap with 1 finger and with 3 fingers. So, I do not get any KeyCodes for swiping on the touchpad or tapping with 2 fingers. That's why I assume that these are not mapped, as in the [Vuzix documentation they have Android KeyCodes](https://www.vuzix.com/Developer/KnowledgeBase/Detail/1110) – made3 Oct 25 '21 at 11:16
  • Hmm interesting. I have found out that seemly `KEYCODE_DPAD_CENTER` is `(KeyCode)10` in Unity, for vuzix devices. And for your case, you can possibly loop over the keycodes and check them. Check my edit. – Timmy Chan Oct 25 '21 at 12:50
  • Did you read that in [this thread](https://stackoverflow.com/questions/54405794/how-to-use-keycode-dpad-center-key-code-in-unity)? With your edit I can find out what KeyCodes are not used, but what then? In the thread I linked they said that KeyCode 10 is not used in Unity, so they can bind `KEYCODE_DPAD_CENTER` to it. But it's just the same as asking for `if(Input.GetKeyDown(10)) ...` which is useless if 10 is not mapped to something? – made3 Oct 25 '21 at 13:31
  • In my edit, you should be able to perform the said actions (swiping or tapping), and get the KeyCodes from them, I believe. At least, you can test out if Unity can at least recognize your actions. I looked at [this link in chinese](https://blog.csdn.net/cordova/article/details/51036547). It says KeyCode 10 is the default keycode. – Timmy Chan Oct 25 '21 at 14:06
  • Thank you! First of all, the touchpad on the device can also be used as a mouse. Normally both the gestures (like swiping) will work simultaneously with the mouse. But in my app I had to deactivate the mouse-feature in the devices settings to receive the keycodes through your code. – made3 Oct 26 '21 at 06:44
1

The solution simply was to deactivate the mouse feature of the Vuzix M400s touchpad. It can be done in the devices settings.

So, these are the KeyCodes for the touchpad:

    private const KeyCode _oneFingerTapKeyCode = (KeyCode)330;
    private const KeyCode _oneFingerHoldKeyCode = (KeyCode)319;
    private const KeyCode _oneFingerSwipeBackKeyCode = (KeyCode)276;
    private const KeyCode _oneFingerSwipeForwardKeyCode = (KeyCode)275;
    private const KeyCode _oneFingerSwipeUpKeyCode = (KeyCode)273;
    private const KeyCode _oneFingerSwipeDownKeyCode = (KeyCode)274;
    private const KeyCode _twoFingerTapKeyCode = (KeyCode)27;
    private const KeyCode _twoFingerHoldKeyCode = (KeyCode)278;
    private const KeyCode _twoFingerSwipeForwardKeyCode = (KeyCode)127;
    private const KeyCode _twoFingerSwipeBackKeyCode = (KeyCode)8;

I have seen them somewhere in a different thread already, but I thought that they did not work, but it was just the mouse input.

made3
  • 89
  • 1
  • 5