Deprecated event for detecting when a key was pressed on the keyboard.
Overview Table Synchronous Yes Bubbles Yes Target [dom/Element](/dom/Element), [dom/Document](/dom/Document) Cancelable Yes Default action Varies: launch text composition system; blur and focus events; DOMActivate event; other eventThis event used to be used to detect when a key value was inserted into the DOM. Developers should use beforeInput, keyup, or keydown events depending on the task instead of this event.
Context informationEvent.target
KeyboardEvent.charCode
KeyboardEvent.keyCode
KeyboardEvent.which
KeyboardEvent.key
KeybaordEvent.location
KeyboardEvent.altKey
KeyboardEvent.shiftKey
KeyboardEvent.ctrlKey
KeyboardEvent.metaKey
KeyboardEvent.repeat
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Keypress event demonstration</title>
<style>
// this styling only exists so things look better on code.webplatform.org
form {
padding-top: 30px;
}
</style>
</head>
<body>
<form>
<label for="keypress">Keypress</label>
<input name="keypress"/>
</form>
<div id="target">
<p>The last key code you entered for keypress is: <span id="keypressEcho"></span></p>
</div>
<script>
var keypressInput = document.getElementsByName('keypress')[0];
var keypressTarget = document.getElementById('keypressEcho');
keypressInput.addEventListener('keypress', function(e) {
keypressTarget.textContent = e.which;
console.log(e.which);
});
</script>
</body>
</html>
Usage
===Related event order===
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4