DEV Community

Cover image for Announcing Keystrokes, successor to KeyboardJS
Robert Hurst
Robert Hurst

Posted on

Announcing Keystrokes, successor to KeyboardJS

It's been seven years since I released of KeyboardJS. Since then web applications have become a lot more sophisticated, TypeScript has come to prominence, and with KeyboardEvent.key now available in all modern browsers, it is no longer necessary to rely on key codes to identify what key was pressed.

As a result of these changes I wanted to take another look at keyboard bindings and see if I could come up with a more modern iteration of KeyboardJS.

I give you Keystrokes, a library for binding keys and key combos to functions. Easy to use and will work in any TypeScript or JavaScript project. It will even work in non browser environments.

Here's an example of a simple key and key combo binding.

import { bindKey, bindKeyCombo } from '@rwh/keystrokes'

bindKey('a', () =>
  console.log('You\'re pressing "a"'))

bindKeyCombo('ctrl > y, r', () =>
  console.log(
    'You pressed "ctrl" then "y", released both, and are ' +
    'pressing "r"'
  ))
Enter fullscreen mode Exit fullscreen mode

Note that is just the surface. You can find out more by checking out the readme.

Any feedback you can provide is greatly appreciated.

Thanks for your time!
-- Robert

Top comments (0)