-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.js
57 lines (51 loc) · 1.06 KB
/
keyboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var keys = {
"w": false,
"a": false,
"s": false,
"d": false,
" ": false,
"x": false,
"b": false,
"ArrowUp": false,
"ArrowRight": false,
"ArrowDown": false,
"ArrowLeft": false
}
function Keypress(e) {
keys[e.key] = true;
}
function KeyUp(e) {
keys[e.key] = false;
}
var mouse = {
pressed: false,
lastPressed: false,
lastPos: {
x: 0,
y: 0
},
x: 0,
y: 0
}
function MouseUp(e) {
if(mouse.pressed == true) {
mouse.pressed = false;
}
}
function MouseDown(e) {
if(mouse.pressed == false) {
mouse.pressed = true;
}
}
function MouseMove(e) {
mouse.x = e.x;
mouse.y = e.y;
}
function MouseWheel(e) {
}
document.addEventListener("keydown", Keypress);
document.addEventListener("keyup", KeyUp);
document.addEventListener("mouseup", MouseUp);
document.addEventListener("mousedown", MouseDown);
document.addEventListener("mousemove", MouseMove);
document.addEventListener("mousewheel", MouseWheel);