#12 Extended helpers for pressed State of shift and ctrl keys

This commit is contained in:
Serraniel 2020-07-29 13:49:05 +02:00
parent 00ef7e75eb
commit cae43ec998
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -1,3 +1,25 @@
var isShiftPressed = false;
var isCtrlPressed = false;
function isHtmlElement(object) { function isHtmlElement(object) {
return object instanceof HTMLElement; return object instanceof HTMLElement;
}
document.addEventListener('keydown', event => handleKeyDown(event));
document.addEventListener('keyup', event => handleKeyUp(event));
function handleKeyDown(event) {
handleKeyToggle(event, true);
}
function handleKeyUp(event) {
handleKeyToggle(event, false);
}
function handleKeyToggle(event, isPressed) {
if (event.key === 'Shift') {
isShiftPressed = isPressed;
} else if (event.key === 'Control') {
isCtrlPressed = isPressed;
}
} }