Package Exports
- ts-keycode
- ts-keycode/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-keycode) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ts-keycode
Installation
$ npm install ts-keycodeImport
/**
* 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)) {
// ...
}
// ...
}
});