Skip to content

silonance/mouse-detection-tool

Repository files navigation

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.

About

mouse-detection-tool

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published