Skip to content

Commit

Permalink
Merge pull request #687 from NextCenturyCorporation/MCS-1925
Browse files Browse the repository at this point in the history
MCS-1925 - [Webenabled] Ignoring non-action keys
  • Loading branch information
rartiss55 authored Aug 18, 2023
2 parents 547ac1f + 27ccd71 commit 66534c3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions webenabled/templates/mcs_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ <h1>Machine Common Sense</h1>
// 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', 'A', 'S', 'D', 'H', 'I', 'J', 'K', 'L', ' ', 'Q']
var processingKeypress = false
// default screen coordinates are in the center of image
var params = {
Expand Down Expand Up @@ -657,14 +657,25 @@ <h1>Machine Common Sense</h1>
window.addEventListener('keydown', this.process_key, false);

function process_key(e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || (arrowKeys.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;
}

if (processingKeypress) {
console.log('Currently processing keypress, ignoring new input.')
return;
}

if (document.getElementById('scene-filename').innerHTML == "None") {
alert("Please select a scene before attempting an action.");
return;
}

hasValidInput = passesValidation(e.key)

if (!hasValidInput) {
Expand Down

0 comments on commit 66534c3

Please sign in to comment.