KeyEvent location Property - Javascript DOM

Javascript examples for DOM:Key Event

Description

The location property tells the location of a key on the keyboard or device.

The location property can only be used on the onkeydown and onkeyup event, not onkeypress.

This property is read-only.

Return Value

A Number, representing the location of a key on the keyboard

The number is represented by 4 constants:

DOM_KEY_LOCATION_STANDARDThe key is not pressed on the right or left side of the keyboard, and was not pressed on the numeric keypad
DOM_KEY_LOCATION_LEFTA left key was pressed, the left "CTRL" key or left "ALT" key
DOM_KEY_LOCATION_RIGHT A right key was pressed, the right "CTRL" key or right "CTRL" key
DOM_KEY_LOCATION_NUMPAD The key was pressed on the numeric keypad

The following code shows how to get the location of the key:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="text" size="40" onkeydown="myFunction(event)">

<p id="demo"></p>

<script>
function myFunction(event) {// ww  w.ja  v  a2 s.  c o  m
    var x = event.location;
    document.getElementById("demo").innerHTML = "Key location: " + x;
}
</script>

</body>
</html>

Related Tutorials