-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
typewriter.js
46 lines (36 loc) · 1.13 KB
/
typewriter.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
const path = require("path");
const pressed = {};
const returnKeyDownSound = new Audio(path.join(__dirname, "audio/return.mp3"));
function handleKeyDown(event) {
if (!pressed[event.keyCode]) {
pressed[event.keyCode] = true;
var key_down = new Audio(path.join(__dirname, "audio/key_down.mp3"));
key_down.play();
if (event.keyCode === 13) {
returnKeyDownSound.pause();
returnKeyDownSound.currentTime = 0.
returnKeyDownSound.play();
}
}
}
function handleKeyUp(event) {
pressed[event.keyCode] = false;
const key_up = new Audio(path.join(__dirname, "audio/key_up.mp3"));
key_up.play();
}
module.exports = {
activate: function(state) {
atom.workspace.observeTextEditors(function(editor) {
const editorView = atom.views.getView(editor);
editorView.addEventListener('keydown', handleKeyDown);
editorView.addEventListener('keyup', handleKeyUp);
});
},
deactivate: function () {
atom.workspace.observeTextEditors(function(editor) {
const editorView = atom.views.getView(editor);
editorView.removeEventListener('keydown', handleKeyDown);
editorView.removeEventListener('keyup', handleKeyUp);
});
}
};