0

What is the correct way to listen on keypress events from the Xbox gamepad?

Buzzwords: UWP, HTML/CSS/JS, React, Typescript

  • The title says “set events” but you ask about “listen on keypress events”. Which do you want? You want to know how to listen to button presses from an Xbox gamepad, right? – Rory O'Kane Feb 27 '18 at 21:50
  • I don't know much about JavaScript support on the Universal Windows Platform, but maybe the [Gamepad API](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API) is available. Edge supports that API, at least. – Rory O'Kane Feb 27 '18 at 21:54
  • This returns null :( – Kenny Wagenknecht Feb 28 '18 at 08:14

2 Answers2

0

You could first listen to the GamepadAdded event. You would get the Gamepad class object by the event args when the the GamepadAdded event is fired.

Then, you could call its GetCurrentReading() method to get which button is pressed.

Xie Steven
  • 8,544
  • 1
  • 9
  • 23
0

Didn't try Xavier's method, we do it like this:

const systemMediaControls = Windows.Media.SystemMediaTransportControls.getForCurrentView(); systemMediaControls.addEventListener('buttonpressed', eventHandler)