Initial import
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Key Press Detection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Press a key to see its code and name:</p>
|
||||
<p id="keyInfo">Key code: <span id="keyCode"></span>, Key name: <span id="keyName"></span></p>
|
||||
|
||||
<script>
|
||||
// Get a reference to the elements for displaying key information
|
||||
const keyInfo = document.getElementById('keyInfo');
|
||||
const keyCodeSpan = document.getElementById('keyCode');
|
||||
const keyNameSpan = document.getElementById('keyName');
|
||||
|
||||
// Add a keypress event listener to the document
|
||||
document.addEventListener('keypress', (event) => {
|
||||
// Get the key code and key name from the event object
|
||||
const keyCode = event.keyCode || event.which;
|
||||
const keyName = event.key;
|
||||
|
||||
// Display the key code and key name
|
||||
keyCodeSpan.textContent = keyCode;
|
||||
keyNameSpan.textContent = keyName;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user