From 80a3511bcb729f952c41f9ccc89e7ba55e5e358c Mon Sep 17 00:00:00 2001 From: neosubhamoy Date: Fri, 27 Sep 2024 14:21:05 +0530 Subject: [PATCH] (refactor): improved keyboard shotcut keyevent detection --- htdocs/assets/js/floatingbar-config.js | 4 ++-- htdocs/assets/js/keybinding-config.js | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/assets/js/floatingbar-config.js b/htdocs/assets/js/floatingbar-config.js index dd505fa..f2c1600 100644 --- a/htdocs/assets/js/floatingbar-config.js +++ b/htdocs/assets/js/floatingbar-config.js @@ -123,7 +123,7 @@ mobileSearchBtn.addEventListener("click", function () { // when ALT + K shortcut key is pressed document.addEventListener("keydown", function(event) { - if (event.altKey && event.key === "k") { + if ((event.altKey && event.key === "k") || (event.altKey && event.key === "K")) { if(!isShareActive) { activate_search(); } @@ -442,7 +442,7 @@ mobileShareCloseBtn.addEventListener("click", function () { // when ALT + L shortcut key is pressed document.addEventListener("keydown", function(event) { - if (event.altKey && event.key === "l") { + if ((event.altKey && event.key === "l") || (event.altKey && event.key === "L")) { if(!isSearchActive) { activate_share(); } diff --git a/htdocs/assets/js/keybinding-config.js b/htdocs/assets/js/keybinding-config.js index 2642fdc..918c3f7 100644 --- a/htdocs/assets/js/keybinding-config.js +++ b/htdocs/assets/js/keybinding-config.js @@ -28,25 +28,25 @@ async function redirectToURL(item) { document.addEventListener('keydown', function(event) { pressedKeys[event.key] = true; - if (pressedKeys['n'] && pressedKeys['h']) { + if ((pressedKeys['n'] && pressedKeys['h']) || (pressedKeys['N'] && pressedKeys['H'])) { window.location.href = basePath; } - else if (pressedKeys['n'] && pressedKeys['p']) { + else if ((pressedKeys['n'] && pressedKeys['p']) || (pressedKeys['N'] && pressedKeys['P'])) { window.location.href = basePath + "/projects"; } - else if (pressedKeys['n'] && pressedKeys['b']) { + else if ((pressedKeys['n'] && pressedKeys['b']) || (pressedKeys['N'] && pressedKeys['B'])) { window.location.href = basePath + "/blog"; } - else if (pressedKeys['n'] && pressedKeys['c']) { + else if ((pressedKeys['n'] && pressedKeys['c']) || (pressedKeys['N'] && pressedKeys['C'])) { window.location.href = basePath + "/contact"; } - else if (pressedKeys['q'] && pressedKeys['e']) { + else if ((pressedKeys['q'] && pressedKeys['e']) || (pressedKeys['Q'] && pressedKeys['E'])) { redirectToURL('email'); } - else if (pressedKeys['q'] && pressedKeys['m']) { + else if ((pressedKeys['q'] && pressedKeys['m']) || (pressedKeys['Q'] && pressedKeys['M'])) { redirectToURL('chat'); } - else if (pressedKeys['q'] && pressedKeys['s']) { + else if ((pressedKeys['q'] && pressedKeys['s']) || (pressedKeys['Q'] && pressedKeys['S'])) { redirectToURL('sources'); } });