Created
August 26, 2022 13:41
-
-
Save bng44270/136280b6fa54adb6a107716efae3b9a7 to your computer and use it in GitHub Desktop.
Get JavaScript keycodes including Shift, Control and Alt combos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Key Code Tester</title> | |
</head> | |
<body> | |
This is an interactive way to view JavaScript keyup and keydown keyCodes including the shift, alt, and ctrl modifier codes.<br/><br/> | |
Key Codes:<br/> | |
<div style="margin-left:50px;height:200px;width:200px;overflow:auto;" id="codeview"></div> | |
<script type="text/javascript"> | |
document.body.onload = function() { | |
document.addEventListener('keyup',(e) => { | |
//Exclude shift, alt, and ctrl | |
if ([16,17,18].indexOf(e.keyCode) == -1) { | |
var mod = []; | |
if (e.ctrlKey) mod.push("ctrl=17"); | |
if (e.altKey) mod.push("alt=18"); | |
if (e.shiftKey) mod.push("shift=16"); | |
document.getElementById('codeview').innerHTML = ((mod.length > 0) ? "(" + mod.join(",") + ") " : "") + e.key.toString() + '=>' + e.keyCode.toString() + '<br/>' + document.getElementById('codeview').innerHTML; | |
} | |
}); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment