-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkeyboard_handler.js
More file actions
54 lines (48 loc) · 1.88 KB
/
Copy pathkeyboard_handler.js
File metadata and controls
54 lines (48 loc) · 1.88 KB
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
var KeyboardHandler = function() {
// Add event listener for keyboard shortcuts
document.addEventListener('keydown', function(event) {
console.log("Key pressed: " + event.key);
switch(event.key) {
case 'p':
case 'P':
console.log("Panic key pressed!");
// Send panic event
var message = {
"type": "panic_inject",
"method": "spatial"
};
ws.send(JSON.stringify(message));
break;
case 'r':
case 'R':
console.log("Random panic key pressed!");
// Send random panic event
var message = {
"type": "panic_inject",
"method": "random"
};
ws.send(JSON.stringify(message));
break;
}
});
this.render = function(model_state) {
// Add instructions for keyboard shortcuts if they don't exist
if (!document.getElementById("keyboard-instructions")) {
console.log("Adding keyboard instructions");
var div = document.createElement("div");
div.id = "keyboard-instructions";
div.innerHTML = "<strong>Keyboard Shortcuts:</strong><br>" +
"Press 'P' to inject panic<br>" +
"Press 'R' to inject random panic";
div.style.position = "fixed";
div.style.bottom = "10px";
div.style.right = "10px";
div.style.backgroundColor = "rgba(0, 0, 0, 0.7)";
div.style.color = "white";
div.style.padding = "10px";
div.style.borderRadius = "5px";
div.style.zIndex = "1000";
document.body.appendChild(div);
}
};
};