-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
37 lines (31 loc) · 898 Bytes
/
script.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
const code = document.querySelector('.code');
const key = document.querySelector('.key');
const pressKey = document.querySelector('.press-key');
const input = document.getElementById('input');
if (window.screen.width >= 1024 && window.screen.height >= 768) {
pressKey.style.display = 'block';
pressKey.innerHTML = 'Press a key';
} else {
input.style.display = 'block';
}
document.addEventListener('textInput', (e) => {
console.log(e.data.charCodeAt(0));
input.value = '';
pressKey.style.display = 'none';
code.innerHTML = e.data.charCodeAt(0);
if (e.data) {
key.style.display = 'block';
key.innerHTML = e.data;
}
});
document.addEventListener('keypress', (e) => {
console.log(e.key);
input.value = '';
pressKey.style.display = 'none';
code.innerHTML = e.keyCode;
// letter
if (e.key) {
key.style.display = 'block';
key.innerHTML = e.key;
}
});