- Home /
Trying to detect the KEYCODE_DPAD_RIGHT and KEYCODE_DPAD_LEFT Android KeyEvents (On Vuzix M400 Glasses)
On Vuzix M400 Glasses I am trying to detect the Android KeyEvents KEYCODE_DPAD_RIGHT source link here KeyEvent and the KEYCODE_DPAD_LEFT KeyEvent.
But Unity does not seem to have a straightforward way to map these key events to a Unity Key Code enum (UnityEngine.KeyCode)
By following the documentation at the Input Manager Class, it says The Input Manager uses three types of controls: Keys, Buttons, and Virtual Axis and it can be accessed at Edit > Project Settings > Input Manager.
On mapping the virtual Axes to controls:
I changed the size to 1, in order to only detect one axis.
Then on "Negative Button" and "Positive Button" properties, I inserted the "joystick button 0" and "joystick button 1".
On Type, I tried to switch from all three options: Key or Mouse button; Mouse Movement; Joystick Axis.
Joy Num: Get motion from all joysticks
Using virtual axes in scripts: I also have registered the axis name as "Horizontal". To see if at runtime it outputs something different than zero. Input.GetAxis("Horizontal") == 0.0
void Update()
{
Debug.Log(Input.GetAxis("Horizontal") == 0.0);
Debug.Log(Input.GetButtonDown("joystick button 1"));
}
To test the interaction of these settings, I attached a gameObject to the main scene and ran on each frame, while pressing the Android touchpad. which yield on the console:
True
And ArgumentException: Input Button joystick button 1 is not setup. To change the input settings use: Edit -> Settings -> Input
But it returned True for every frame, with means the program failed to query the current value of the Horizontal axis. And It also seems that I did not setup the joystick button 1 correctly.
Documentation also says that I can access the keys from the Unity KeyCodes enumeration. So I tried to detect if the KEYCODE_DPAD_RIGHT and KEYCODE_DPAD_LEFT were triggered from the KeyCodes available, even though knowing that keys are specific to a physical keyboard.
foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKey(kcode))
Debug.Log("KeyCode down: " + kcode);
}
Answer by heromade · Oct 22, 2021 at 09:09 AM
@zetiagocosta Did you find a solution for it? I am still trying to figure out how to get input from the Vizux M400 in Unity. I can move the mouse but I can not press Unity UI buttons or select a Unity UI button with the physical buttons on the glasses...