Use keycodes for UWP xbox instead of gamepadtokey.

This commit is contained in:
Bradley Eaton
2025-06-24 13:27:19 +01:00
parent 42c71dcb97
commit a7d443ab23
6 changed files with 73 additions and 3 deletions
+6
View File
@@ -1243,6 +1243,12 @@ export default function (view) {
if (layoutManager.tv && !currentVisibleMenu) {
// Change the behavior of some keys when the OSD is hidden
switch (key) {
case 'NavigationLeft':
case 'NavigationRight':
case 'GamepadLeftThumbLeft':
case 'GamepadLeftThumbRight':
case 'GamepadDPadLeft':
case 'GamepadDPadRight':
case 'ArrowLeft':
case 'ArrowRight':
if (!e.shiftKey) {
+2 -1
View File
@@ -79,7 +79,8 @@ function onMouseDown(e) {
}
function onKeyDown(e) {
if (e.keyCode === 13 && !enableNativeMenu()) {
// Xbox controller for UWP WebView2 uses keycode 195 to select.
if (e.keyCode === 13 && !enableNativeMenu() || (e.keyCode === 195 && browser.edgeChromium)) {
e.preventDefault();
showActionSheet(this);
}
+6
View File
@@ -527,12 +527,18 @@ function stepKeyboard(elem, delta) {
*/
function onKeyDown(e) {
switch (keyboardnavigation.getKeyName(e)) {
case 'NavigationLeft':
case 'GamepadDPadLeft':
case 'GamepadLeftThumbLeft':
case 'ArrowLeft':
case 'Left':
stepKeyboard(this, -normalizeSliderStep(this, this.keyboardStepDown));
e.preventDefault();
e.stopPropagation();
break;
case 'NavigationRight':
case 'GamepadDPadRight':
case 'GamepadLeftThumbRight':
case 'ArrowRight':
case 'Right':
stepKeyboard(this, normalizeSliderStep(this, this.keyboardStepUp));
+6
View File
@@ -138,12 +138,18 @@ export class BookPlayer {
if (!this.loaded) return;
switch (key) {
case 'NavigationRight':
case 'GamepadDPadRight':
case 'GamepadLeftThumbRight':
case 'l':
case 'ArrowRight':
case 'Right':
e.preventDefault();
this.next();
break;
case 'NavigationLeft':
case 'GamepadDPadLeft':
case 'GamepadLeftThumbLeft':
case 'j':
case 'ArrowLeft':
case 'Left':
+6
View File
@@ -97,12 +97,18 @@ export class PdfPlayer {
const key = keyboardnavigation.getKeyName(e);
switch (key) {
case 'NavigationRight':
case 'GamepadDPadRight':
case 'GamepadLeftThumbRight':
case 'l':
case 'ArrowRight':
case 'Right':
e.preventDefault();
this.next();
break;
case 'NavigationLeft':
case 'GamepadDPadLeft':
case 'GamepadLeftThumbLeft':
case 'j':
case 'ArrowLeft':
case 'Left':
+47 -2
View File
@@ -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)
@@ -43,7 +68,10 @@ const KeyNames = {
/**
* Keys used for keyboard navigation.
*/
const NavigationKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'BrowserHome', 'Find'];
const NavigationKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'BrowserHome', 'Find',
'NavigationUp', 'NavigationDown', 'NavigationLeft', 'NavigationRight',
'GamepadDPadUp', 'GamepadDPadDown', 'GamepadDPadLeft', 'GamepadDPadRight',
'GamepadLeftThumbUp', 'GamepadLeftThumbDown', 'GamepadLeftThumbLeft', 'GamepadLeftThumbRight'];
/**
* Keys used for media playback control.
@@ -145,6 +173,9 @@ export function enable() {
let capture = true;
switch (key) {
case 'NavigationLeft':
case 'GamepadDPadLeft':
case 'GamepadLeftThumbLeft':
case 'ArrowLeft':
if (!isInteractiveElement(document.activeElement)) {
inputManager.handleCommand('left');
@@ -152,9 +183,15 @@ export function enable() {
capture = false;
}
break;
case 'NavigationUp':
case 'GamepadDPadUp':
case 'GamepadLeftThumbUp':
case 'ArrowUp':
inputManager.handleCommand('up');
break;
case 'NavigationRight':
case 'GamepadDPadRight':
case 'GamepadLeftThumbRight':
case 'ArrowRight':
if (!isInteractiveElement(document.activeElement)) {
inputManager.handleCommand('right');
@@ -162,10 +199,17 @@ export function enable() {
capture = false;
}
break;
case 'NavigationDown':
case 'GamepadDPadDown':
case 'GamepadLeftThumbDown':
case 'ArrowDown':
inputManager.handleCommand('down');
break;
case 'GamepadA':
inputManager.handleCommand('select');
break;
case 'GamepadB':
case 'Back':
inputManager.handleCommand('back');
break;
@@ -239,7 +283,8 @@ function attachGamepadScript() {
}
// No need to check for gamepads manually at load time, the eventhandler will be fired for that
if (navigator.getGamepads && appSettings.enableGamepad()) {
// Not needed for UWP
if (navigator.getGamepads && appSettings.enableGamepad() && !browser.xboxOne) {
window.addEventListener('gamepadconnected', attachGamepadScript);
}