Skip to content

thiagogarbazza/key-code

Repository files navigation

key-code

Build Status License

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

Installation

Using NPM

npm install --save key-code

Using Bower

bower install --save key-code

Usage

Using NodeJs

Include the package using CommonJS require()

var KeyCode = require('key-code');

or ES2015 import:

// ES2015+
import KeyCode from 'key-code';

Using Browser

<!-- 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');
    }
}

License

The key-code project is under MIT license.