@asnow-io/keycodejs
v0.0.2
Published
An enum of frequent keycodes
Downloads
3
Readme
KeycodeJS
An enum of frequent keycodes.
Install
npm install @asnow-io/keycodejs
Usage
import { Keycode, wasPressed } from '@asnow-io/keycodejs';
const textField = document.getElementById('#text-field');
function sendMessage() {
// ...
}
textField.addEventListener('keydown', (e) => {
if (wasPressed(e, Keycode.ENTER)) {
e.preventDefault();
sendMessage();
}
// `wasPressed(e, Keycode.ENTER)`
// equals
// `e.code === Keycode.ENTER`
})
Typings
enum Keycode {
BACKSPACE = 'Backspace',
TAB = 'Tab',
ENTER = 'Enter',
// and others
}
function wasPressed(e: KeyboardEvent, key: string | string[]): boolean;