Skip to content
On this page

usePointerLock

Category
Export Size
Last Changed
2 months ago

Reactive pointer lock.

Demo

Basic Usage

js
import { usePointerLock } from '@vueuse/core'

const { isSupported, lock, unlock, element, triggerElement } = usePointerLock()
import { usePointerLock } from '@vueuse/core'

const { isSupported, lock, unlock, element, triggerElement } = usePointerLock()

Component Usage

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

html
<UsePointerLock v-slot="{ lock }">
  <canvas />
  <button @click="lock">
    Lock Pointer on Canvas
  </button>
</UsePointerLock>
<UsePointerLock v-slot="{ lock }">
  <canvas />
  <button @click="lock">
    Lock Pointer on Canvas
  </button>
</UsePointerLock>

Type Declarations

typescript
declare global {
  interface PointerLockOptions {
    unadjustedMovement?: boolean
  }
  interface Element {
    requestPointerLock(options?: PointerLockOptions): Promise<void> | void
  }
}
type MaybeHTMLElement = HTMLElement | undefined | null
export interface UsePointerLockOptions extends ConfigurableDocument {
  pointerLockOptions?: PointerLockOptions
}
/**
 * Reactive pointer lock.
 *
 * @see https://vueuse.org/usePointerLock
 * @param target
 * @param options
 */
export declare function usePointerLock(
  target?: MaybeElementRef<MaybeHTMLElement>,
  options?: UsePointerLockOptions
): {
  isSupported: Ref<boolean>
  element: Ref<MaybeHTMLElement>
  triggerElement: Ref<MaybeHTMLElement>
  lock: (
    e: MaybeElementRef<MaybeHTMLElement> | Event,
    options?: PointerLockOptions
  ) => Promise<HTMLElement>
  unlock: () => Promise<boolean>
}
export type UsePointerLockReturn = ReturnType<typeof usePointerLock>
declare global {
  interface PointerLockOptions {
    unadjustedMovement?: boolean
  }
  interface Element {
    requestPointerLock(options?: PointerLockOptions): Promise<void> | void
  }
}
type MaybeHTMLElement = HTMLElement | undefined | null
export interface UsePointerLockOptions extends ConfigurableDocument {
  pointerLockOptions?: PointerLockOptions
}
/**
 * Reactive pointer lock.
 *
 * @see https://vueuse.org/usePointerLock
 * @param target
 * @param options
 */
export declare function usePointerLock(
  target?: MaybeElementRef<MaybeHTMLElement>,
  options?: UsePointerLockOptions
): {
  isSupported: Ref<boolean>
  element: Ref<MaybeHTMLElement>
  triggerElement: Ref<MaybeHTMLElement>
  lock: (
    e: MaybeElementRef<MaybeHTMLElement> | Event,
    options?: PointerLockOptions
  ) => Promise<HTMLElement>
  unlock: () => Promise<boolean>
}
export type UsePointerLockReturn = ReturnType<typeof usePointerLock>

Source

SourceDemoDocs

Contributors

Sergey Danilchenko

Changelog

v9.11.0 on 1/17/2023
ae69f - feat: new function (#2590)

Released under the MIT License.