#12 Extended helpers for pressed State of shift and ctrl keys
This commit is contained in:
parent
00ef7e75eb
commit
cae43ec998
|
@ -1,3 +1,25 @@
|
|||
var isShiftPressed = false;
|
||||
var isCtrlPressed = false;
|
||||
|
||||
function isHtmlElement(object) {
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue