ts-keycode
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

ts-keycode

NPM Latest Version Downloads Count Bundle Size Test Status Last Update Date Project License

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)) {
           
           // ...
           
       }
       // ...

   } 
});

My Social Network Links

Twitter Profile

LinkedIn Profile

GitHub Profile

medium.com Profile

Package Sidebar

Install

npm i ts-keycode

Weekly Downloads

3

Version

0.0.1

License

MIT

Unpacked Size

42.1 kB

Total Files

44

Last publish

Collaborators

  • karbash