# pointer-lock

> pointer lock polyfill that presents an eventemitter / stream api

Latest version **0.0.4** (published 2013-01-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install pointer-lock
pnpm add pointer-lock
yarn add pointer-lock
bun add pointer-lock
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2013-01-05 |
| First published | 2013-01-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Chris Dickinson |
| Maintainers | chrisdickinson |
| Keywords | pointer-lock, pointer, lock, browserify |

## Links

- npm: https://www.npmjs.com/package/pointer-lock
- Repository: https://github.com/chrisdickinson/pointer-lock
- npm.io page: https://npm.io/package/pointer-lock

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2013-01-05
- 0.0.3 — 2013-01-05
- 0.0.2 — 2013-01-05
- 0.0.1 — 2013-01-05
- 0.0.0 — 2013-01-05

## README

# pointer-lock

pointer-lock api exposed as an event emitter that emits readable streams
of mouse movement data. automatically handles adding appropriate mousedown/up
event listeners on the targeted element. tries to reuse objects instead of creating
new objects, to keep garbage generation low. may sing you songs, if you're nice
enough to it.

```javascript
var lock = require('pointer-lock')
  , my_element = document.getElementById('element')

if(!lock.available())
  return alert('not available!')

// my_element can be any element currently attached to
// the document -- but not the document itself (document.body on down
// is fine.)
var pointer = lock(my_element)

pointer.on('attain', function(movements) {
  var initial = {x: movements.x, y: movements: y}

  // movements is a readable stream
  movements.on('data', function(move) {
    // be sure to copy the data *out of* move,
    // as the move object is reused.
    initial.x += move.dx
    initial.y += move.dy
    initial.t += move.dt
  })

  movements.on('close', function() {
    // no more movements from this pointer-lock session.
  })
})

pointer.on('release', function() {
  // pointer has been released
})

pointer.on('error', function() {
  // user denied pointer lock OR it's not available
})

pointer.on('needs-fullscreen', function() {
  // some browsers require you to be in fullscreen mode
  // for pointer lock.
  // this lets you catch that case and request it after
  // you've requested fullscreen.
  var fullscreen = require('fullscreen')
    , fs = fullscreen(my_element)

  fs.once('attain', function() {
    // manually re-request pointer lock
    pointer.request()
  })

  // request fullscreen!
  fs.request()
})

// request pointer lock: warning, may require being called from a mouse event listener
pointer.request()

// releases the pointer lock session, if any.
pointer.release()

// current pointer lock element, if any.
pointer.target()

// remove the mouse event listeners added by lock
pointer.destroy()

```

# license

MIT

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