1.0.1 • Published 4 years ago

@ivanhanak_com/keycodes v1.0.1

Weekly downloads
1
License
https://www.imdb....
Repository
github
Last release
4 years ago

browser consistent "was a key pressed" checker

npm.io NPM Weekly Downloads

A simple javascript library helping with dealing with browser inconsistencies of browser Event.code and Event.keyCode implementation for the most used keys.

Changelog

See the whole Changelog.

Install

Using npm:

npm install @ivanhanak_com/keycodes

Using yarn:

yarn add @ivanhanak_com/keycodes

Usage

import {
    hasShiftKeyBeenPressed,
    cmdMacKeyHasBeenPressed,
    enterKeyHasBeenPressed,
    escKeyHasBeenPressed,
    spaceKeyHasBeenPressed,
    tabKeyHasBeenPressed,
    arrowRightKeyHasBeenPressed,
    arrowLeftKeyHasBeenPressed,
    arrowUpKeyHasBeenPressed,
    arrowDownKeyHasBeenPressed,
} from '@ivanhanak_com/keycodes';


document.addEventListener("keydown", e => {
    if(hasShiftKeyBeenPressed(e) && tabKeyHasBeenPressed(e)) {
        //...do something on ...tab+shift
    }
    
    if(arrowDownKeyHasBeenPressed(e)) {
        //...do something on ...arrow down
    }

});

Browser support

IE, Chrome, Firefox, Safari