Folder structure
This commit is contained in:
1 parent
946059650f
commit
2ed630a9cd
13 files changed
+2
-2
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import {DEFAULT_KEYPRESS_DELAY} from './constants.js';
|
||||
|
||||
const input = {};
|
||||
let lastKeypressTime = 0;
|
||||
|
||||
document.addEventListener('keydown', (e) => {input[e.key] = true; e.preventDefault()});
|
||||
document.addEventListener('keyup', (e) => {input[e.key] = false; e.preventDefault()});
|
||||
|
||||
export function key(key) {
|
||||
return input[key]
|
||||
}
|
||||
|
||||
export function afterKeyDelay(amount=DEFAULT_KEYPRESS_DELAY) {
|
||||
const now = Date.now();
|
||||
if (now - lastKeypressTime >= amount) {
|
||||
lastKeypressTime = now;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user