-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (32 loc) · 1 KB
/
Copy pathscript.js
File metadata and controls
43 lines (32 loc) · 1 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
/**
* Generates HTML markup displaying key event information.
*
* @param {string} key - The key value pressed by the user.
* @param {string} code - The physical key code identifier.
* @param {number|string} keyCode - The Unicode value of the key pressed.
* @returns {string} HTML string containing key, code, and key code information.
*/
const container = document.getElementById("keyContainer");
container.innerHTML = generateHTML("-", "-", "-")
window.addEventListener("keydown", (e) => {
container.innerHTML = generateHTML(e.key, e.code, e.key.charCodeAt(0));
});
function generateHTML(key, code, keyCode) {
return `
<div class="key-container">
<h4>Key</h4>
<div class="key-content">${key === " " ? "Space" : key}
</div>
</div>
<div class="key-container">
<h4>Code</h4>
<div class="key-content">${code}
</div>
</div>
<div class="key-container">
<h4>Key Code</h4>
<div class="key-content">${keyCode}
</div>
</div>
`;
}