DEV Community

Omri
Omri

Posted on

3 3

Dead Simple Keyboard shortcut management library for Angular

I have always liked the way Visual Studio Code enabled you to modify/add key binding in a JSON object, which is a pretty nice interface in my opinion.
Taken as an insperation, I wanted to create a similar and scalable solution for Angular application.
To achieve a pretty scale-able solution keeping mind memory leakage and garbage collection of registered shortcut in a large app. Thus a component based architecture was chosen.

The library supports both Windows and Mac, has a nice built in help screen to show all registered shortcuts and service to create a customize help screen in need.

You can find the library here:
And play with a working example here

How it works

  1. To optimize for performance, only one event listener is registered to the document body.
  2. Each shortcut is then checked when keydown is pressed (this part can still be optimized and will be in the future, but the filtering is pretty quick at the moment so even with 100 registered shortcuts no slowdown are noticeable)
  3. You can use a directive to target a shortcut to work only when a specific element is in focus
  4. Or use a component that will add a global shortcut to your application, and will be cleaned out automatically when the component is destroyed.

Feedback

This is the first library I publish to NPM, any feedback, code related, documentation or anything at all will be greatly appreciated.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series