npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mousehawk

v0.1.4

Published

The mouse counterpart to https://github.com/robertcorponoi/keyhawk. Mousehawk is used to create and manage mouse button bindings for your games.

Downloads

7

Readme

Mousehawk

The mouse counterpart to Keyhawk. Mousehawk is used to create and manage mouse button bindings for your games.

NPM version Known Vulnerabilities npm NPM downloads Gitter

Mousehawk lets you easily and quickly create mouse button binds for your JavaScript games. Mouse button binds, or "mousebinds" are creating by assigning a mouse button to be bound and then passing a method that should be run when the mousebind is active (the button for it is pressed) and an optional delay that can be used to limit how often the mousebind can be used.

Mousehawk also gives you the option of using the default game loop module that is used to check for which buttons are pressed or you can use your own loop and just use the exposed API.

Installation

Mousehawk is an ES6 module that can be used by downloading the package through NPM:

$ npm install mousehawk

Initialization

Mousehawk upon initialization can be passed an options object and for now there is just one option that can be specified.

| param | type | description | default | |-----------------|---------|------------------------------------------------------------------------------------------------------------------------|---------| | options | Object | | {} | | options.useLoop | boolean | Indicates whether Mousehawk should use the default game loop module for checking if a mousebind is actively being used | true |

Basic Example

To begin using Mousehawk, simply import the default module from wherever its located and specify as an option of whether you would like to use the built in game loop or not.

import Mousehawk from './path/to/Mousehawk.js';


const mousehawk = new Mousehawk();

Creating mousebinds

To create a new mousebind, you start out by using the mousebind method which takes a single argument of the mouse button to listen for.

The buttons that can be assigned to a mousebinds should be derived from the Mousehawk.BUTTON Object as these have been normalized and ensured to work.

An example of creating a mousebinds can be done as shown:

mousehawk.mousebind(mousehawk.BUTTON.MOUSE_2);

Just this mousebind on its own doesn't do much as there's no action associated with it. To add a function to run when the mousebind is active, you can specify an action:

function hello() {

    console.log('Hello!');

}

mousehawk.mousebind(mousehawk.BUTTON.MOUSE_2).action(hello);

This will run the hello method everytime the mousebind is active.

Notice how action can be chained, this is because mousebind returns an instance of the mousebind and so it could be written as:

function hello() {

  console.log('Hello!');

}

const sayHello = mousehawk.mousebind(mousehawk.BUTTON.MOUSE_2);

sayHello.action(hello);

Lastly, you can add a delay to the mousebind so that a certain amount of time has to pass between uses. This does not apply to the very first press though which means that if you set a delay of 5000ms you don't have to wait 5000ms to use it for the first time it will be available immediately but after that it will rest for 5000ms.

function hello() {

  console.log('Hello!');

}

const sayHello = mousehawk.mousebind(mousehawk.BUTTON.MOUSE_1).action(hello).delay(5000);

initialDelay

Sets the initial delay before the mousebind can be used for the first time

| param | type | description | default | |------- |-------- |----------------------------------------------------------- |--------- | | ms | number | The time in milliseconds before the mousebind can be used. | |

mousehawk.initialDelay(5000);

Disable/Enable

To diable the use of any and all mousebinds you can call the disable method.

mousehawk.disable();

This method also takes an optional parameter which specifies how long you want mousebinds to be disabled for. So for instance if you used mousehawk.disable(10000) all mousebinds are going to be disabled for 10 seconds and they will be enabled again. If no time is provided then it is set to Infinity and you will have to call

mousehawk.enable();

to re-enable the use of mousebinds.

Using Your Own Game Loop

If you are already using a game loop for another purpose then you should set the useLoop option to false so that the Mousehawk game loop and your game loop aren't both running at the same time. Mousehawk exposes the update method which is what checks for active mousebinds and you can call that within your project inside of your game loop.

const mousehawk = new Mousehawk({ useLoop: false });

// Set up your mousebinds here...

// And inside of your game loop, call the following method providing the current time from your loop:
mousehawk.check(time);

Tests

To run the tests available for Mousehawk, use:

$ npm run test

and then in your browser navigate to http://localhost:8888/test/index.html.

License

MIT