From 17f948018815946cbcbf8540397046e4ed1e3a28 Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo Date: Wed, 5 Feb 2020 15:20:48 +0300 Subject: [PATCH] Disable keyboard navigation for non-TV --- src/components/keyboardnavigation.js | 27 +++++++++++++++++++++++++-- src/controllers/playback/videoosd.js | 7 +------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/components/keyboardnavigation.js b/src/components/keyboardnavigation.js index d1ed03138c..4f3ed873d9 100644 --- a/src/components/keyboardnavigation.js +++ b/src/components/keyboardnavigation.js @@ -36,6 +36,11 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager) 10252: "MediaPlayPause" }; + /** + * Keys used for keyboard navigation. + */ + var NavigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"]; + var hasFieldKey = false; try { hasFieldKey = "key" in new KeyboardEvent("keydown"); @@ -60,11 +65,28 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager) return KeyNames[event.keyCode] || event.key; } + /** + * Returns _true_ if key is used for navigation. + * + * @param {string} key name + * @return {boolean} _true_ if key is used for navigation + */ + function isNavigationKey(key) { + return NavigationKeys.indexOf(key) != -1; + } + function enable() { document.addEventListener("keydown", function (e) { + var key = getKeyName(e); + + // Ignore navigation keys for non-TV + if (!layoutManager.tv && isNavigationKey(key)) { + return; + } + var capture = true; - switch (getKeyName(e)) { + switch (key) { case "ArrowLeft": inputManager.handle("left"); break; @@ -128,6 +150,7 @@ define(["inputManager", "layoutManager"], function (inputManager, layoutManager) return { enable: enable, - getKeyName: getKeyName + getKeyName: getKeyName, + isNavigationKey: isNavigationKey }; }); diff --git a/src/controllers/playback/videoosd.js b/src/controllers/playback/videoosd.js index 122b2c8080..fd42f68498 100644 --- a/src/controllers/playback/videoosd.js +++ b/src/controllers/playback/videoosd.js @@ -1087,11 +1087,6 @@ define(["playbackManager", "dom", "inputManager", "datetime", "itemHelper", "med } } - /** - * Keys used for keyboard navigation. - */ - var NavigationKeys = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"]; - /** * Clicked element. * To skip 'click' handling on Firefox/Edge. @@ -1109,7 +1104,7 @@ define(["playbackManager", "dom", "inputManager", "datetime", "itemHelper", "med return; } - if (layoutManager.tv && NavigationKeys.indexOf(key) != -1) { + if (layoutManager.tv && keyboardnavigation.isNavigationKey(key)) { showOsd(); return; }