mouse-detection-tool

1.0.2 • Public • Published

MouseDetection

Detects the prescence of a mouse as reliably as possible.
Live demo

The problem

There is currently no 100% way to detect the prescence of a mouse in the browser without making false assumptions. This project attempts to solve this problem.

How?

This project detects the prescence of a mouse based on event acceleration from the mousemove event within a timeframe. If a certain number of events are reached within a specific timeframe it will assume the prescence of a mouse. A promise is resolved when the mouse is detected.

Installation

npm i mouse-detection

Usage

import { MouseDetection } from 'mouse-detection';

MouseDetection({ // this configuration object is optional
  eventLimitCount: 4, // number of events to listen for within the timespan
  eventLimitTimeSpan: 200, // the timespan in ms
})
  .then(() => {
    console.log('mouse detected.');
  });

Why cant I see if a mouse is present right away?

This is not possible since we always have to start on the assumption that we don't know if a mouse exists. The user has to prove this to be false. It's only once the mouse starts moving that we can actually make a reasonable assumption that it's there.

Package Sidebar

Install

npm i mouse-detection-tool

Weekly Downloads

12

Version

1.0.2

License

MIT

Unpacked Size

11.2 kB

Total Files

10

Last publish

Collaborators

  • yamatende