xbox one controller prevent default back button behavior with Javascript

耗尽温柔 提交于 2021-01-29 11:14:18

问题


I have an xbox one app that has a webview containing a javascript app.

In my React app I have something like this:

navigator.gamepadInputEmulation = 'gamepad';

window.addEventListener('onkeydown', function(event) {
  if (event.keyCode === 196) {
    event.stopImmediatePropagation();
    // custom back button logic
  }
});

The custom back button logic runs but then the default controller back button logic also runs even with event.stopImmediatePropagation(); Is there any fix for this?

If I set navigator.gamepadInputEmulation = 'keyboard'; this issue goes away but then all the controller input events run twice.


回答1:


Here is a quick fix for you, just intercept the 'backrequested' and set it as handled:

var systemNavManager = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
systemNavManager.addEventListener("backrequested", (event)=>event.handled = true, false);

Hope that helps!



来源:https://stackoverflow.com/questions/56981247/xbox-one-controller-prevent-default-back-button-behavior-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!