JavaScript DOM KeyboardEvent property: location
[this page | pdf | back links]
The location property
of KeyboardEvent
objects within the JavaScript
DOM (i.e.
events triggered by an action with the keyboard) returns the location of the
key on the keyboard or device.
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Try pressing a key in this input box:
<input style="background-color: yellow; border: 2px solid black; width: 200px; height: 100px;"
onkeypress="myOnkeypress(event)"><br><br>
KeyboardEvent outcomes are:<br><br>
altKey: <b id="key1"></b><br>
charCode: <b id="key2"></b><br>
ctrlKey: <b id="key3"></b><br>
key: <b id="key4"></b><br>
keyCode: <b id="key5"></b><br>
location: <b id="key6"></b><br>
metaKey: <b id="key7"></b><br>
shiftKey: <b id="key8"></b><br>
which: <b id="key9"></b><br>
<script>
function myOnkeypress(event) {
document.getElementById("key1").innerHTML = event.altKey;
document.getElementById("key2").innerHTML = event.charCode;
document.getElementById("key3").innerHTML = event.ctrlKey;
document.getElementById("key4").innerHTML = event.key;
document.getElementById("key5").innerHTML = event.keyCode;
document.getElementById("key6").innerHTML = event.location;
document.getElementById("key7").innerHTML = event.metaKey;
document.getElementById("key8").innerHTML = event.shiftKey;
document.getElementById("key9").innerHTML = event.which;
}
</script>
</body>
</html>
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)