Library for key-code constants in ECMAScript/Javascript
For more information see this.
See key-code.js for a full list of all the constants
npm install --save key-code
bower install --save key-code
Include the package using CommonJS require()
var KeyCode = require('key-code');
or ES2015 import:
// ES2015+
import KeyCode from 'key-code';
<!-- Load files. -->
<script src="/path/to/key-code/dist/key-code.js"></script>
<input type="text" onkeydown="myFunction(event)">
function myFunction(event) {
if (event.keyCode === KeyCode.ENTER) {
alert('keypress ENTER');
}
}
Using Browser via CDN - jsdelivr
<!-- Load files. -->
<script src="https://cdn.jsdelivr.net/npm/key-code@0.0.1/dist/key-code.js"></script>
<input type="text" onkeydown="myFunction(event)">
function myFunction(event) {
if (event.keyCode === KeyCode.ENTER) {
alert('keypress ENTER');
}
}
The key-code
project is under MIT license.