# mouse-event

> Cross browser mouse event property access

Latest version **1.0.5** (published 2015-04-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install mouse-event
pnpm add mouse-event
yarn add mouse-event
bun add mouse-event
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2015-04-26 |
| First published | 2015-02-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 29 |
| Author | Mikola Lysenko |
| Maintainers | mikolalysenko |
| Keywords | mouse, event, buttons, which, button, element, target, srcelement, polyfill, fix, portable, firefox, chrome, mousevent, click, left, right, middle, fix, bug |

## Links

- npm: https://www.npmjs.com/package/mouse-event
- Repository: https://github.com/mikolalysenko/mouse-event
- Issues: https://github.com/mikolalysenko/mouse-event/issues
- npm.io page: https://npm.io/package/mouse-event

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2015-04-26
- 1.0.4 — 2015-04-13
- 1.0.3 — 2015-04-13
- 1.0.2 — 2015-02-17
- 1.0.1 — 2015-02-16
- 1.0.0 — 2015-02-16

## README

# mouse-event
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.

# Example

```javascript
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](https://mikolalysenko.github.io/mouse-event)

# Install

```
npm i mouse-event
```

# API

```javascript
var mouse = require('mouse-event')
```

#### `mouse.buttons(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

#### `mouse.x(event)`
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

#### `mouse.y(event)`
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

#### `mouse.element(event)`
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

# License
(c) 2015 Mikola Lysenko. MIT License

---
_Source: https://npm.io/package/mouse-event · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
