JSFiddle - React, Tailwind, and code Playground
TypeScript
var _ctrlKeyPressed: boolean = false;
var keyEventName: string = 'keydown';
$(document).on(keyEventName, (e: any) => {
var ke: any = e || <any>window.event;
var keyCode = ke.which || ke.keyCode;
switch (keyCode) {
case 17: {
this._ctrlKeyPressed = true;
console.log('Ctrl');
break;
}
case 83: {
//Block Ctrl+S
if (this._ctrlKeyPressed) {
e.preventDefault();
e.stopPropagation();
this._ctrlKeyPressed = false;
console.log('Ctrl+S');
}
break;
}
case 87: {
//Block Ctrl+W --Not work in Chrome
if (this._ctrlKeyPressed) {
this._ctrlKeyPressed = false;
e.preventDefault();
e.stopPropagation();
console.log('Ctrl+W');
}
break;
}
case 78: {
//Ctrl+N
if (this._ctrlKeyPressed) {
this._ctrlKeyPressed = false;
e.preventDefault();
e.stopPropagation();
console.log('Ctrl+N');
}
break;
}
case 69: {
//Ctrl+E
if (this._ctrlKeyPressed) {
this._ctrlKeyPressed = false;
console.log('Ctrl+E');
}
break;
}
case 90: {
//Ctrl+Z
if (this._ctrlKeyPressed) {
this._ctrlKeyPressed = false;
console.log('Ctrl+Z');
}
break;
}
}
});