-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard.js
56 lines (54 loc) · 1.95 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
CLOCKWORKRT.components.register([
{
name: "keyboard",
description: "This component allows you to incorporate keyboard support to your game, sending key events that other components can listen to.",
events: [
{
name: "#setup", code: function (event) {
var names = ["keyup", "keydown"];
var tokens = [];
for (var i in names) {
tokens[i] = this.execute_event.bind(this, names[i]);
window.addEventListener(names[i], tokens[i], false);
}
this.setVar("eventstoken", tokens);
}
},
{
name: "#exit", code: function (event) {
var tokens = this.getVar("eventstoken");
var names = ["keyup", "keydown"];
for (var i in names) {
window.removeEventListener(names[i], tokens[i], false);
}
}
},
{
name: "keydown", code: function (event) {
this.engine.execute_event("keyboardDown", { key: event.keyCode });
}
},
{
name: "keyup", code: function (event) {
this.engine.execute_event("keyboardUp", { key: event.keyCode });
}
}
],
triggers: [
{
"name": "keyboardDown",
"description": "This event will be triggered once a key is pressed.",
"dataSchema": {
"key": "<The key code>"
}
},
{
"name": "keyboardUp",
"description": "This event will be triggered once a key is released.",
"dataSchema": {
"key": "<The key code>"
}
}
]
}
]);