ts-keycode
v0.0.1
Published
The package for check some data in typescript.
Downloads
28
Maintainers
Readme
ts-keycode
Installation
$ npm install ts-keycode
Import
/**
* It is a map with all keyboard codes
*/
import {keycode} from 'ts-keycode';
/**
* Or if you need segregate by segemnts:
* accents,
* alphabet,
* commands,
* f,
* functions,
* numbers,
* numpad,
* operators,
* select
*
* Use it below
*/
import {keycodeSegments} from 'ts-keycode';
Examples
import {NumbersEnum} from 'ts-keycode/consts/numbers';
import {NumpadEnum} from 'ts-keycode/consts/numpad';
const twoFactorId: string = 'authorization-login-form-two-factor-code';
const inputTwoFactor: HTMLInputElement = document.getElementById(twoFactorId);
// ...
const allowKeyboardCodesMap: (typeof NumbersEnum | typeof NumpadEnum)[] = {
...NumbersEnum,
...NumpadEnum
};
// ...
inputTwoFactor.addEventListener('keydown', ($event) => {
if ($event?.isTrusted) {
// ...
const keycode: number = $event.which ?? $event.keyCode;
if (allowKeyboardCodes.hasOwnProperty(keycode)) {
// ...
}
// ...
}
});