Skip to content

Commit

Permalink
Command hotkeys escaped instead of executed Techtonica#45
Browse files Browse the repository at this point in the history
  • Loading branch information
Katherine Shambaugh committed Oct 1, 2020
1 parent d1c7d7c commit b09969a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 53 deletions.
87 changes: 36 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dotenv": "^8.1.0",
"ejs": "^3.0.1",
"express": "^4.17.1",
"http-server": "^0.11.1",
"http-server": "^0.12.3",
"morgan": "^1.9.1",
"mysql": "^2.17.1",
"path": "^0.12.7",
Expand Down
16 changes: 15 additions & 1 deletion public/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var reqKeys = []
var typewriter;
var quesNo;
let pressed = new Set();
var commandDown = false;

// event.keyCode Chrome and Firefox
const CHROME_LEFT_COMMAND_CODE = 91;
Expand Down Expand Up @@ -82,6 +83,9 @@ function handle(e) {
$("#"+e.code.toLowerCase()).toggleClass("pressed");
}
if(e.key.toLowerCase()=="alt" || e.key.toLowerCase()=="shift" || e.key.toLowerCase()=="meta"){
if (e.key.toLowerCase()=="meta") {
commandDown = true;
}
let keyString = e.code;
if(e.code == FIREFOX_LEFT_COMMAND_STRING) {
keyString = CHROME_LEFT_COMMAND_STRING
Expand All @@ -100,7 +104,14 @@ function handle(e) {
$('.letter').toggleClass('uppercase');
caps=false;
}
else $("#"+e.key.toLowerCase() ).addClass("pressed");
else {
if (commandDown) {
e.preventDefault();
e.stopPropagation();
return false;
}
$("#"+e.key.toLowerCase() ).addClass("pressed");
}
}

// Function called on KeyUp to reset the key by removing class = 'pressed'
Expand All @@ -109,6 +120,9 @@ function release(e) {
$("#"+e.code.toLowerCase()).removeClass("pressed");
}
if(e.key.toLowerCase()=="alt" || e.key.toLowerCase()=="shift" || e.key.toLowerCase()=="meta"){
if (e.key.toLowerCase()=="meta") {
commandDown = false;
}
let keyString = e.code;
if(e.code == FIREFOX_LEFT_COMMAND_STRING) {
keyString = CHROME_LEFT_COMMAND_STRING
Expand Down

0 comments on commit b09969a

Please sign in to comment.