blob: d6345193efe65c4bfdde544c283f51f8a1b85c00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
export function setUpKeyboard() {
document.addEventListener("keyup", k => trigger(k))
document.addEventListener("keydown", k => trigger(k))
}
export const keys = {
right: false,
left: false,
up: false,
down: false,
shoot: false,
}
function trigger(event) {
let on = event.type == "keydown"
switch (event.key) {
case "ArrowRight": keys.right = on; break;
case "ArrowLeft": keys.left = on; break;
case "ArrowUp": keys.up = on; break;
case "ArrowDown": keys.down = on; break;
case "z": case "Z": keys.shoot = on; break;
}
}
|