JavaScript KeyboardEvent location Property
You are Here:
JavaScript KeyboardEvent location Property
The event.location
property returns a number that indicates the location of a key on the keyboard or other input device.
Note: This property is read-only.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<input type="text" onkeydown="myFunction(event)">
<p>Location of key pressed: <span id="point"></span></p>
<script>
function myFunction(e){
document.getElementById("point").innerHTML = e.location;
}
</script>
</body>
</html>
Syntax
event.location
Return Value
The following table is based on a standard 101 key US keyboard.
Value | Explanation |
---|---|
0 | DOM_KEY_LOCATION_STANDARD When "A", "SPACE", "3 (on the top of alphabets side)" keys are pressed. |
1 | DOM_KEY_LOCATION_LEFT When left hand side "ctrl", "alt", "shift", "cmd", "windows" keys are pressed. |
2 | DOM_KEY_LOCATION_RIGHT When right hand side "ctrl", "alt", "shift", "cmd", "windows" keys are pressed. |
3 | DOM_KEY_LOCATION_NUMPAD. When numbers like "1", "2" on the numeric keypad are pressed. |
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.