Auto-add Keyboard Shortcuts To Links – HuntAndHotkey

Category: Javascript | October 29, 2024
AuthorCaleb4man
Last UpdateOctober 29, 2024
LicenseMIT
Views23 views
Auto-add Keyboard Shortcuts To Links – HuntAndHotkey

HuntAndHotkey is a lightweight JavaScript library that automatically adds keyboard shortcuts to links and buttons on web pages.

It appends number or letter indicators next to links and binds corresponding keyboard keys. This enables your visitors quickly access links without using a mouse.

How to use it:

1. Add the HuntAndHotkey.js file to your HTML page.

<script src="HuntAndHotkey.js"></script>

2. Place the links you want to hotkey within a container element with the class HotkeyTarget:

<div class="HotkeyTarget">
  <a href="https://www.jqueryscript.net">jQueryScript</a>
  ... more links here ...
  <a href="https://www.cssscript.com">CSSScript</a>
</div>

3. Call the assignHotkeysToLinks function and provide a string of characters as the argument. Each character will be assigned sequentially as a hotkey to each link. In this example, pressing “1” opens the jQueryScript link, pressing “2” opens the CSSScript link, and so on.

HuntAndHotkey.assignHotkeysToLinks("1234567890qwert")

4. The library also supports web buttons.

HuntAndHotkey.assignHotkeysToButtons('1234567890qwert', '<{key}>');
HuntAndHotkey.assignHotkeysToLinksAndButtons('1234567890qwert', '[{key}]')

Changelog:

10/29/2024

  • Added format parameter

You Might Be Interested In:


Leave a Reply