Skip to content

A simple Javascript library that makes it easier to manually set the repeat rate for a held down key

Notifications You must be signed in to change notification settings

mattfan00/holdjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

hold.js

hold.js is a Javascript library that brings the feel of a native application to the web. Traditionally, when you hold down a key in the browser, the operating system chooses the repeat speed of the character. However, hold.js gives the developer the freedom of setting the repeat speed in an easy to use library. hold.js is ideal for creating browser games.

How to use it

  1. Include hold.js in your application

    <script src="https://cdn.jsdelivr.net/gh/mattfan00/holdjs@latest/main.js"></script>
  2. Use hold.add() to start listening for a specific key. Additionally, include the repeat speed (in milliseconds) and the function associated with that key.

    hold.add('f', 1000, () => {
      console.log('Holding down the f-key will press the f-key once every second');
    }));
  3. Use hold.remove() to stop listening for that key.

    hold.remove('f');

Features?

  • Works for keys commonly used in browser games!

    hold.add('left', 100, () => { console.log('Left arrow key!') });
    hold.add('right', 100, () => { console.log('Right arrow key!') });
    hold.add('up', 100, () => { console.log('Up arrow key!') });
    hold.add('down', 100, () => { console.log('Down arrow key!') });
    hold.add('space', 100, () => { console.log('Spacebar key!') });
  • Chain keys together!

    hold.add('a b c', 200, () => {
      console.log('Listen to a, b, and c');
    }));

See it in action

Visit our website for a demo!

About

A simple Javascript library that makes it easier to manually set the repeat rate for a held down key

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published