This commit is contained in:
Jade (Rose) Rowland 2024-12-30 21:49:59 -05:00
parent e71db24073
commit 42519581c1
3 changed files with 8987 additions and 10861 deletions

View file

@ -434,6 +434,25 @@ function getUnixTimeSeconds() {
return Date.now() * 0.001;
}
let keyState;
export function getCurrentKeyboardState() {
if (keyState == null) {
keyState = {};
// Listen for the keydown event to mark the key as pressed
window.addEventListener('keydown', (event) => {
keyState[event.key] = true; // Mark the key as pressed
});
// Listen for the keyup event to mark the key as released
window.addEventListener('keyup', (event) => {
keyState[event.key] = false; // Mark the key as released
});
}
return { ...keyState }; // Return a shallow copy of the key state object
}
// Floating point versions, see Fraction for rational versions
// // greatest common divisor
// export const gcd = function (x, y, ...z) {