node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »



Provides a normalized, cross-browser, garbage-collection-free API for reading out the state of a mouse event.

Why is this needed?

Because it is 2015 and somehow every major browser still disagrees on even the most basic details of MouseEvents. Seriously guys.


var mouse = require('mouse-event')
window.addEventListener('mousemove', function(ev) {
  document.body.innerHTML =
    '<p>Buttons: ' + mouse.buttons(ev) + 
    ' x:' + mouse.x(ev) + 
    ' y:' + mouse.y(ev) + '</p>'

Try this in your browser


npm i mouse-event


var mouse = require('mouse-event')


Returns a bit vector, similar to event.which in WebKit encoding the state of the mouse buttons.

  • event is a mouse event

Returns A bit vector with the following interpretation for the flags:

  • 1 - left mouse
  • 2 - right mouse
  • 4 - middle mouse
  • 8 - button 4
  • 16 - button 5
  • ...
  • 1<<k - button k+1


Returns the relative x-coordinate of the mouse event

  • event is a mouse event

Returns The relative x-coordinate of event, similar to event.x in WebKit


Returns the relative y-coordinate of the mouse event

  • event is a mouse event

Returns The relative y-coordinate of event, similar to event.y in WebKit


Get the element which triggered the event.

  • event is a mouse event

Returns The target or srcElement or whatever it was that triggered the event


(c) 2015 Mikola Lysenko. MIT License