Merge pull request #6993 from brad1111/uwp-xbox-controller-fix
Use keycodes for UWP controller instead of gamepadtokey.
This commit is contained in:
@@ -290,7 +290,7 @@ browser.hisense = userAgent.toLowerCase().includes('hisense');
|
||||
browser.tizen = userAgent.toLowerCase().indexOf('tizen') !== -1 || window.tizen != null;
|
||||
browser.vidaa = userAgent.toLowerCase().includes('vidaa');
|
||||
browser.web0s = isWeb0s();
|
||||
browser.edgeUwp = browser.edge && (userAgent.toLowerCase().indexOf('msapphost') !== -1 || userAgent.toLowerCase().indexOf('webview') !== -1);
|
||||
browser.edgeUwp = (browser.edge || browser.edgeChromium) && (userAgent.toLowerCase().indexOf('msapphost') !== -1 || userAgent.toLowerCase().indexOf('webview') !== -1);
|
||||
|
||||
if (browser.web0s) {
|
||||
browser.web0sVersion = web0sVersion(browser);
|
||||
|
||||
@@ -20,6 +20,31 @@ const KeyNames = {
|
||||
38: 'ArrowUp',
|
||||
39: 'ArrowRight',
|
||||
40: 'ArrowDown',
|
||||
|
||||
// UWP WebView section start --
|
||||
// Navigation Up/Down/Left/Right is part of TVJS directionalnavigation-1.0.0.0.js
|
||||
// Unsure what this is used for. Media remote?
|
||||
138: 'NavigationUp',
|
||||
139: 'NavigationDown',
|
||||
140: 'NavigationLeft',
|
||||
141: 'NavigationRight',
|
||||
195: 'GamepadA',
|
||||
// Currently Xbox UWP WebView 2 sends code 27 (Escape instead) despite being undocumented
|
||||
// Desktop UWP unchanged
|
||||
196: 'GamepadB',
|
||||
203: 'GamepadDPadUp',
|
||||
204: 'GamepadDPadDown',
|
||||
205: 'GamepadDPadLeft',
|
||||
206: 'GamepadDPadRight',
|
||||
// Currently Xbox UWP WebView 2 sends Arrow keycodes despite being undocumented
|
||||
// Desktop UWP unchanged
|
||||
// Left Thumbstick
|
||||
211: 'GamepadLeftThumbUp',
|
||||
212: 'GamepadLeftThumbDown',
|
||||
214: 'GamepadLeftThumbLeft',
|
||||
213: 'GamepadLeftThumbRight',
|
||||
// End of UWP WebView Section
|
||||
|
||||
// MediaRewind (Tizen/WebOS)
|
||||
412: 'MediaRewind',
|
||||
// MediaStop (Tizen/WebOS)
|
||||
@@ -40,6 +65,23 @@ const KeyNames = {
|
||||
10252: 'MediaPlayPause'
|
||||
};
|
||||
|
||||
const KeyAliases = {
|
||||
// GamepadA needs special case handling
|
||||
GamepadB: 'Escape',
|
||||
NavigationUp: 'ArrowUp',
|
||||
NavigationDown: 'ArrowDown',
|
||||
NavigationLeft: 'ArrowLeft',
|
||||
NavigationRight: 'ArrowRight',
|
||||
GamepadDPadUp: 'ArrowUp',
|
||||
GamepadDPadDown: 'ArrowDown',
|
||||
GamepadDPadLeft: 'ArrowLeft',
|
||||
GamepadDPadRight: 'ArrowRight',
|
||||
GamepadLeftThumbUp: 'ArrowUp',
|
||||
GamepadLeftThumbDown: 'ArrowDown',
|
||||
GamepadLeftThumbLeft: 'ArrowLeft',
|
||||
GamepadLeftThumbRight: 'ArrowRight'
|
||||
};
|
||||
|
||||
/**
|
||||
* Keys used for keyboard navigation.
|
||||
*/
|
||||
@@ -81,7 +123,8 @@ if (!hasFieldKey) {
|
||||
* @return {string} Key name.
|
||||
*/
|
||||
export function getKeyName(event) {
|
||||
return KeyNames[event.keyCode] || event.key;
|
||||
const key = KeyNames[event.keyCode] || event.key;
|
||||
return KeyAliases[key] || key;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,6 +209,9 @@ export function enable() {
|
||||
inputManager.handleCommand('down');
|
||||
break;
|
||||
|
||||
case 'GamepadA':
|
||||
inputManager.handleCommand('select');
|
||||
break;
|
||||
case 'Back':
|
||||
inputManager.handleCommand('back');
|
||||
break;
|
||||
@@ -230,6 +276,11 @@ export function enable() {
|
||||
});
|
||||
}
|
||||
|
||||
export function canEnableGamepad() {
|
||||
// Not needed for UWP
|
||||
return !browser.edgeUwp;
|
||||
}
|
||||
|
||||
// Gamepad initialisation. No script is required if no gamepads are present at init time, saving a bit of resources.
|
||||
// Whenever the gamepad is connected, we hand all the control of the gamepad to gamepadtokey.js by removing the event handler
|
||||
function attachGamepadScript() {
|
||||
@@ -239,12 +290,13 @@ function attachGamepadScript() {
|
||||
}
|
||||
|
||||
// No need to check for gamepads manually at load time, the eventhandler will be fired for that
|
||||
if (navigator.getGamepads && appSettings.enableGamepad()) {
|
||||
if (navigator.getGamepads && appSettings.enableGamepad() && canEnableGamepad()) {
|
||||
window.addEventListener('gamepadconnected', attachGamepadScript);
|
||||
}
|
||||
|
||||
export default {
|
||||
enable: enable,
|
||||
getKeyName: getKeyName,
|
||||
isNavigationKey: isNavigationKey
|
||||
isNavigationKey,
|
||||
canEnableGamepad
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user