DEV Community

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

Posted on

1 1

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

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay