Lightweight Key Binding JavaScript Library – Keybinder

Category: Javascript | December 4, 2022
Author:codad5
Views Total:19 views
Official Page:Go to website
Last Update:December 4, 2022
License:MIT

Preview:

Lightweight Key Binding JavaScript Library – Keybinder

Description:

A lightweight key binding library that listens for keypress events and makes it easy to add shortcuts to your app.

With this library, you can trigger certain events with a specific key (or key shortcuts), making it potentially useful for anyone looking to facilitate keyboard control of their applications.

How to use it:

1. Import the KeyBinder.

<script type="module">
  import { KeyBinder } from './dist/cjs/index.js';
</script>

2. Create a new Keybinder instance and pass the following parameters:

  • default_listener: ‘keypress’, ‘keydown’, ‘keyup’, etc.
  • element: In which container the library listens for key events
  • case_sensitive: Case sensitive or not
const keyController = new KeyBinder({
      default_listener: 'keypress',
      element: window,
      case_sensitive: false
})

3. Create your own keyboard shortcuts.

// single key
keyController.ListenToKey('enter', (data) => {
  // do something
});
// combination
keyController.ListenToKey('ctrl+c', () => {
  // do something
});
// multiple shortcuts
keyController.ListenToKey('ctrl+c', 'ctrl+v' () => {
  // do something
});

Changelog:

12/04/2022

  • Bugfix

You Might Be Interested In:


Leave a Reply