Code Monkey home page Code Monkey logo

global-mouse-events's Introduction

global-mouse-events

Global mouse events listener for Node.js (Windows only). Based off of sentialx/mouse-hooks and coldKey1/mouse-hooks.

Installation

npm i global-mouse-events

Usage

Import the module and register for the mouse events you'd like to listen to.

Available event listeners

mouseup / mousedown - Fires when a mouse button is pressed / released.
Returns:

  • x: The X position of the mouse, relative to the top left of the primary display.
  • y: The Y position of the mouse, relative to the top left of the primary display.
  • button: Which button was pressed. 1 is left-click. 2 is right-click. 3 is middle-click.

mousemove - Fires when the mouse cursor is moved.
Returns:

  • x: The X position of the mouse, relative to the top left of the primary display.
  • y: The Y position of the mouse, relative to the top left of the primary display.

mousewheel - Fires when the mouse wheel is scrolled. Some trackpads may not fire this event unless "Scroll inactive windows when I hover over them" is disabled in the Windows settings.
Returns:

  • x: The X position of the mouse, relative to the top left of the primary display.
  • y: The Y position of the mouse, relative to the top left of the primary display.
  • delta: How much the mouse wheel was scrolled. Positive numbers are considered "up" and negative numbers are "down".
  • axis: Whether the scroll was vertical or horizontal. 0 is vertical. 1 is horizontal.

Example

const mouseEvents = require("global-mouse-events");

mouseEvents.on("mouseup", event => {
  console.log(event); // { x: 2962, y: 483, button: 1 }
});

mouseEvents.on("mousedown", event => {
  console.log(event); // { x: 2962, y: 483, button: 1 }
});

mouseEvents.on("mousemove", event => {
  console.log(event); // { x: 2962, y: 482 }
});

mouseEvents.on("mousewheel", event => {
  console.log(event); // { x: 2962, y: 483, delta: -1, axis: 0 }
});

global-mouse-events's People

Contributors

capure avatar djsweet avatar samx avatar sentialx avatar xanderfrangos avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.