title: Access Oculus Go Controller via GamePad API in Oculus Browser?
body: <p>I'm testing out a couple of my three.js apps in my new Oculus Go. I'm wondering if it's possible to access the controller just using the GamePad API that seems to be available today with the major browsers. </p>
  
  <p>Looking at the Oculus documentation, it seems like it can be done through the OVRManager that comes with Unity, or through UnReal Blueprints. But I'm trying to avoid another learning curve, as well as bulking up my apps if I can avoid it. </p>
  
  <p>As a newbie to VR, it seems the most favorable way to proceed would simply be with using the Gamepad API by doing something like this (the guts of this isn't working code just yet, but I'm trying to get at the problem with this sort of approach, and no results so far other than breaking the app when I go into VR mode): </p>
  
  <pre><code>var gamePadState = {
    lastButtons: {},
    lastAxes: {}
  };
  
  function onGamePad(){
  
      Array.prototype.forEach.call( navigator.getGamepads(), function (activePad, padIndex){
        if ( activePad.connected ) {
          if (activePad.id.includes("Oculus Go")) {
            // Process buttons and axes for the Gear VR touch panel
            activePad.buttons.forEach( function ( gamepadButton, buttonIndex ){
              if ( buttonIndex === 0 &amp;&amp; gamepadButton.pressed &amp;&amp; !lastButtons[buttonIndex]){
                // Handle tap
                dollyCam.translateZ( -0.01 );
              }
              gamePadState.lastButtons[buttonIndex] = gamepadButton.pressed;
            });
  
            activePad.axes.forEach( function (axisValue, axisIndex ) {
              if (axisIndex === 0 &amp;&amp; axisValue &lt; 0 &amp;&amp; lastAxes[axisIndex] &gt;= 0 ){
                // Handle swipe right
              } else if (axisIndex === 0 &amp;&amp; axisValue &gt; 0 &amp;&amp; lastAxes[axisIndex] &lt;= 0) {
                // Handle swipe left
              } else if (axisIndex === 1 &amp;&amp; axisValue &lt; 0 &amp;&amp; lastAxes[axisIndex] &gt;= 0) {
                // Handle swipe up
              } else if (axisIndex === 1 &amp;&amp; axisValue &gt; 0 &amp;&amp; lastAxes[axisIndex] &lt;= 0) {
                // Handle swipe down
              }
              gamePadState.lastAxes[axisIndex] = axisValue;
            });
          } else {
            // This is a connected Bluetooth gamepad which you may want to support in your VR experience
          }
        }
      });
  
  }
  </code></pre>
  
  <p>In <a href="https://stackoverflow.com/questions/53162597/how-to-include-ovrmanager-in-three-js-scene">another, narrower question</a> I posed on this topic, I was advised to create a Unity build in my app to get the results I wanted, which seems like both an additional learning curve, plus bulking up my overhead. I'll do it if I have to, but I'd rather not, if I don't.</p>
  
  <p>Ultimately I'd like to be able to support most of the "major" controllers using logic like this: </p>
  
  <pre><code>onGamePad( event ){
  
      var gamePads = navigator.getGamepads();
  
      if ( gamePads &amp;&amp; gamePads.length &gt; 0 &amp;&amp; event.isSomeGamePadEventOfSomeSort ){
          for ( var p = 0; p &lt; gamePads.length; p ++ ){
              if ( gamePads[ p ].id.includes( "Oculus Go" ) ){
                  // process buttons and axes for the Oculus Go Controller here
                  if ( event[ some property... gamePad?? ].id.includes( "Oculus Go" ) &amp;&amp; event[ some property... gamePad?? ].button.pressed === someIndex ){
                      doSomething();              
                  }
              }
              else if ( gamePads[ p ].id.includes( "Oculus Gear VR" ){
                  // Process buttons and axes for the Oculus Gear VR Controller here...
              }
          }
      }
  
  }
  </code></pre>
  
  <p>But for testing purposes I'd be grateful just to get the Oculus Go controller going for now.</p>
  
  <p>So... Is it possible to access the Oculus Go controller via the Gamepad API, and how can I access the device properties such as buttons, axes and orientation, and related gamepad events?</p>
  
  <p>Thanks.</p>