Skip to content

Instantly share code, notes, and snippets.

@sioniks
Created February 5, 2020 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sioniks/cf17ebef1440cdc4d08d953dd45ce958 to your computer and use it in GitHub Desktop.
Save sioniks/cf17ebef1440cdc4d08d953dd45ce958 to your computer and use it in GitHub Desktop.
report key event
function reportKeyEvent (zEvent) {
var keyStr = ["Control", "Shift", "Alt", "Meta"].includes(zEvent.key) ? "" : zEvent.key + " ";
var reportStr =
"The " +
( zEvent.ctrlKey ? "Control " : "" ) +
( zEvent.shiftKey ? "Shift " : "" ) +
( zEvent.altKey ? "Alt " : "" ) +
( zEvent.metaKey ? "Meta " : "" ) +
keyStr + "key was pressed."
;
$("#statusReport").text (reportStr);
//--- Was a Ctrl-Alt-E combo pressed?
if (zEvent.ctrlKey && zEvent.altKey && zEvent.key === "e") { // case sensitive
this.hitCnt = ( this.hitCnt || 0 ) + 1;
$("#statusReport").after (
'<p>Bingo! cnt: ' + this.hitCnt + '</p>'
);
}
zEvent.stopPropagation ();
zEvent.preventDefault ()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment