Nobody Prefers Margarine

    keyboard-handler

    2.0.0 • Public • Published

    keyboard-handler Build Status npm version Coverage Status

    Single handler for all browser keyboard events.

    Appends a single listener for keyboard events, using the document.addEventListener function. See the API section for available helper functions, when key(s) are pressed and released.

    Install

    $ npm install --save keyboard-handler
    

    Usage

    import * as keyboard from 'keyboard-handler'
    keyboard.keyPressed(e => {
      console.log(e.which)
    })
    // => 27

    API

    keysAreDown(codes, cb)

    Calls cb if all codes are held down.

    codes

    Type: array

    cb

    Type: function

    keyIsDown(code, cb)

    Calls cb when a certain key code is pressed.

    code

    Type: number

    cb

    Type: function

    keyPressed(cb)

    Calls cb when any key is pressed.

    cb

    Type: function

    keyReleased(cb)

    Calls cb when any key is released.

    cb

    Type: function

    License

    MIT © Emil Johansson

    Install

    npm i keyboard-handler

    DownloadsWeekly Downloads

    1

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    9.54 kB

    Total Files

    8

    Last publish

    Collaborators

    • emiljohansson