-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXT-Keyboard.js
88 lines (81 loc) · 2.18 KB
/
EXT-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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/****************
* EXT-Keyboard *
* Bugsounet *
* 02/2024 *
*****************/
Module.register("EXT-Keyboard", {
defaults: {
debug: false,
keyFinder: false,
keys: [
{
keyCode: 107,
notification: "EXT_VOLUME-SPEAKER_UP",
payload: null,
command: null,
sound: "up"
},
{
keyCode: 109,
notification: "EXT_VOLUME-SPEAKER_DOWN",
payload: null,
command: null,
sound: "down"
}
]
},
start () {
this.resources = "/modules/EXT-Keyboard/resources/";
this.audio = null;
},
getDom () {
var wrapper = document.createElement("div");
wrapper.style.display = "none";
return wrapper;
},
notificationReceived (noti, payload, sender) {
switch (noti) {
case "GA_READY":
if (sender.name === "MMM-GoogleAssistant") {
this.sendSocketNotification("INIT", this.config);
this.prepare();
this.sendNotification("EXT_HELLO", this.name);
}
break;
}
},
socketNotificationReceived (noti, payload) {
switch (noti) {
case "WARNING":
this.sendNotification("GA_ALERT", {
type: "warning",
message: payload.message,
sound: `${this.resources}keyboard.mp3`
});
break;
}
},
prepare () {
this.audio = new Audio();
this.audio.autoplay = true;
onkeydown = (event) => {
if (this.config.keyFinder) {
this.sendNotification("GA_ALERT", {
type: "information",
message: `You pressed: ${event.key === " " ? "Space" : event.key}. keyCode is: ${event.keyCode}`,
timer: 3000,
sound: `${this.resources}keyboard.mp3`
});
}
if (this.config.keys.length && Array.isArray(this.config.keys)) {
this.config.keys.forEach((key) => {
if (key.keyCode === event.keyCode) {
if (key.notification) this.sendNotification(key.notification, key.payload || undefined);
if (key.command) this.sendSocketNotification("SHELLEXEC", key.command);
if (key.sound) this.audio.src = `${this.resources + key.sound}.mp3`;
}
});
}
};
}
});