I'm trying to figure out when the user presses the control key in an HTML page using JavaScript.
In the following code "CTRL UP" will appear as expected, but "CTRL DOWN" will only appear if I also press another key, e.g. shift.
<html>
<head>
<script type="text/javascript">
window.addEventListener("keyup", function(event) {
// Bind to both command (for Mac) and control (for Win/Linux)
if (event.ctrlKey) {
console.log("CTRL UP");
}
}, false);
window.addEventListener("keydown", function(event) {
// Bind to both command (for Mac) and control (for Win/Linux)
if (event.ctrlKey) {
console.log("CTRL DOWN");
}
}, false);
</script>
</head>
<body>
Ctrl Demo
</body>
</html>
Is there any way to get the "CTRL DOWN" key event to work as expected, when ctrl is pressed and held down by itself?
NOTE: I'm trying to get this to work in a Google Chrome extension, so using Chrome specific APIs or tricks to make this work is completely fine. I'm using Google Chrome 15.0.874.83 beta on Ubuntu.