From fe9d20028c9a08a6adb4fd9c48dd954d97df58b4 Mon Sep 17 00:00:00 2001 From: Artiss Date: Mon, 14 Aug 2023 15:53:00 -0400 Subject: [PATCH 1/3] Ignoring non-action keys (MCS-1925). --- webenabled/templates/mcs_page.html | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/webenabled/templates/mcs_page.html b/webenabled/templates/mcs_page.html index a93faf7b..7db84f0f 100644 --- a/webenabled/templates/mcs_page.html +++ b/webenabled/templates/mcs_page.html @@ -360,7 +360,8 @@

Machine Common Sense

// Handle clicking on one of the scene file names var sceneSelect = document.getElementById("scenes-dropdown"); let actionKeysWithParams = ['1', '3', '4', '5', '6', '7', '8', '9', 'm', 'M', 't', 'T'] - let arrowKeys = ["ArrowDown", "ArrowUp", "ArrowLeft", "ArrowRight"] + let allOtherActionKeys = ['2', 'w', 'W', 'a', 'A', 's', 'D', 'h', 'H', 'i', 'I', 'j', + 'J', 'k', 'K', 'L', 'l', ' ', 'q', 'Q'] var processingKeypress = false // default screen coordinates are in the center of image var params = { @@ -650,14 +651,21 @@

Machine Common Sense

window.addEventListener('keydown', this.process_key, false); function process_key(e) { - if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || (arrowKeys.includes(e.key))) { + if((!actionKeysWithParams.includes(e.key)) && (!allOtherActionKeys.includes(e.key))) { return; } + if (processingKeypress) { console.log('Currently processing keypress, ignoring new input.') return; } + var sceneFilename = document.getElementById('scene-filename'); + if (sceneFilename.innerHTML == "None") { + alert("Please select a scene before attempting an action."); + return; + } + hasValidInput = passesValidation(e.key) if (!hasValidInput) { From 6fdbe8e96bd212b35cc8c84b41cf7b9352b27ef1 Mon Sep 17 00:00:00 2001 From: Artiss Date: Mon, 14 Aug 2023 15:59:19 -0400 Subject: [PATCH 2/3] Update variable reference (MCS-1925). --- webenabled/templates/mcs_page.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/webenabled/templates/mcs_page.html b/webenabled/templates/mcs_page.html index 7db84f0f..8ad24889 100644 --- a/webenabled/templates/mcs_page.html +++ b/webenabled/templates/mcs_page.html @@ -660,8 +660,7 @@

Machine Common Sense

return; } - var sceneFilename = document.getElementById('scene-filename'); - if (sceneFilename.innerHTML == "None") { + if (document.getElementById('scene-filename').innerHTML == "None") { alert("Please select a scene before attempting an action."); return; } From 27ccd710f47be0e0f82efa806c4b710b075cb9d2 Mon Sep 17 00:00:00 2001 From: Artiss Date: Thu, 17 Aug 2023 16:32:58 -0400 Subject: [PATCH 3/3] Addressing PR comments. --- webenabled/templates/mcs_page.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/webenabled/templates/mcs_page.html b/webenabled/templates/mcs_page.html index 8ad24889..51edd413 100644 --- a/webenabled/templates/mcs_page.html +++ b/webenabled/templates/mcs_page.html @@ -360,8 +360,7 @@

Machine Common Sense

// Handle clicking on one of the scene file names var sceneSelect = document.getElementById("scenes-dropdown"); let actionKeysWithParams = ['1', '3', '4', '5', '6', '7', '8', '9', 'm', 'M', 't', 'T'] - let allOtherActionKeys = ['2', 'w', 'W', 'a', 'A', 's', 'D', 'h', 'H', 'i', 'I', 'j', - 'J', 'k', 'K', 'L', 'l', ' ', 'q', 'Q'] + let allOtherActionKeys = ['2', 'W', 'A', 'S', 'D', 'H', 'I', 'J', 'K', 'L', ' ', 'Q'] var processingKeypress = false // default screen coordinates are in the center of image var params = { @@ -651,7 +650,12 @@

Machine Common Sense

window.addEventListener('keydown', this.process_key, false); function process_key(e) { - if((!actionKeysWithParams.includes(e.key)) && (!allOtherActionKeys.includes(e.key))) { + // avoid scrolling with spacebar/Pass action + if(e.keyCode == 32) { + e.preventDefault(); + } + + if((!actionKeysWithParams.includes(e.key)) && (!allOtherActionKeys.includes(e.key.toUpperCase()))) { return; }