How to Get Button Events

Introduction

Note

WaveVR_ButtonList will be deprecated. Please use WaveVR_ButtonManager instead.

You can refer to Buttons for the deprecated WaveVR_ButtonList component.

VIVE Wave™ Provides the WaveVR_ButtonManager component in Assets/WaveVR/Scripts/Button folder to use the device buttons.

I.Enables / Disables Buttons

  1. Drags the prefab Assets/WaveVR/Prefabs/ButtonManager into your scene.

    _images/HowToGetButtonEvent_01.png
  2. Inside the ButtonManager prefab, you can see the Hmd Options, Dominant Options and Non Dominant Options.

    _images/HowToGetButtonEvent_02.png
  3. Selects the button checkbox to enable specific buttons.

    You can use following sample code to enable or disable the button in runtime:

void Update()
{
        if (WaveVR_ButtonManager.Instance == null)
                return;

        // Enables the dominant trigger button.
        WaveVR_ButtonManager.Instance.DominantOptions.Trigger = true;
        // Enables the non-dominant thumbstick button.
        WaveVR_ButtonManager.Instance.NonDominantOptions.Thumbstick = true;
}

II.Gets Button Events

The code format is:

bool ret = WaveVR_Controller.Input(<device type>).<button event function>(<button ID>);

There are device types defined as:

public enum EDeviceType
{
        Head = 1,
        Dominant = 2,
        NonDominant = 3
};

The dominant hand is the right controller in right-handed mode but is the left controller in left-handed mode.

There are button event functions defined as:

public bool GetPress(WVR_InputId _id);      // whether button is pressed.
public bool GetPressDown(WVR_InputId _id)   // whether button is pressed from unpressed, only 1 frame.
public bool GetPressUp(WVR_InputId _id)     // whether button is released from pressed, only 1 frame.
public bool GetTouch(WVR_InputId _id)       // whether button is touched.
public bool GetTouchDown(WVR_InputId _id)   // whether button is touched from untouched, only 1 frame.
public bool GetTouchUp(WVR_InputId _id)     // whether button is untouched from touched, only 1 frame.

There are button IDs defined as:

public enum WVR_InputId
{
        // All buttons have press state.
        WVR_InputId_Alias1_Menu            = WVR_InputId_1,  /**< Menu Button. */
        WVR_InputId_Alias1_Grip            = WVR_InputId_2,  /**< Grip Button. */
        WVR_InputId_Alias1_DPad_Left       = WVR_InputId_3,  /**< DPad_Left Button in physical, or simulated by Touchpad Left pressed event. */
        WVR_InputId_Alias1_DPad_Up         = WVR_InputId_4,  /**< DPad_Up Button in physical, or  simulated by Touchpad Up pressed event. */
        WVR_InputId_Alias1_DPad_Right      = WVR_InputId_5,  /**< DPad_Right Button in physical, or simulated by Touchpad Right pressed event. */
        WVR_InputId_Alias1_DPad_Down       = WVR_InputId_6,  /**< DPad_Down Button in physical, or simulated by Touchpad Down pressed event. */
        WVR_InputId_Alias1_Volume_Up       = WVR_InputId_7,  /**< Volume_Up Button. */
        WVR_InputId_Alias1_Volume_Down     = WVR_InputId_8,  /**< Volume_Down Button. */
        WVR_InputId_Alias1_Bumper          = WVR_InputId_9,  /**< Bumper Button. */
        WVR_InputId_Alias1_A               = WVR_InputId_10, /**< Button A. */
        WVR_InputId_Alias1_B               = WVR_InputId_11, /**< Button B. */
        WVR_InputId_Alias1_Back            = WVR_InputId_14, /**< Hmd Back Button */
        WVR_InputId_Alias1_Enter           = WVR_InputId_15, /**< Hmd Enter Button */
        // Buttons with ID less than or equal to 15 does NOT have touch state.

        // Buttons with ID more than 15 have touch state.
        WVR_InputId_Alias1_Touchpad        = WVR_InputId_16, /**< Touchpad input device. */
        WVR_InputId_Alias1_Trigger         = WVR_InputId_17, /**< Trigger input device. */
        WVR_InputId_Alias1_Thumbstick      = WVR_InputId_18, /**< Thumbstick input device. */
};

So if you want to know whether the device Dominant button Touchpad is Press Down, the code is:

bool pressed = WaveVR_Controller.Input(WaveVR_Controller.EDeviceType.Dominant).GetPressDown(WVR_InputId.WVR_InputId_Alias1_Touchpad)

III.Checks Available Buttons

If you cannot get a specific button event, you can using following code to check if the button is available:

void Update()
{
        if (WaveVR_ButtonManager.Instance == null)
                return;

        // Checks if dominant trigger button is available.
        bool dominant_trigger_isAvailable = WaveVR_ButtonManager.Instance.IsButtonAvailable(WaveVR_Controller.EDeviceType.Dominant, WaveVR_ButtonList.EButtons.Trigger);
        // Checks if non-dominant grip button is available.
        bool nonDominant_grip_isAvailable = WaveVR_ButtonManager.Instance.IsButtonAvailable(WaveVR_Controller.EDeviceType.NonDominant, WaveVR_ButtonList.EButtons.Grip);
}