Document: pointerlockchange event
Pointer Lock API
Pointer Lock API
The pointerlockchange event is fired when the pointer is locked/unlocked.
The event handler can use Document.pointerLockElement to determine whether the pointer is locked, and if so, to which element it is locked.
This event is not cancelable and does not bubble.
Syntax
Use the event name in addEventListener():
addEventListener("pointerlockchange", (event) => { })
Alternatively, assign to the event handler property of the interface:
onpointerlockchange = (event) => { }
Event type
A generic Event.
Examples
Using addEventListener():
document.addEventListener("pointerlockchange", (event) => {
if (document.pointerLockElement)
console.log("The pointer is locked to: ", document.pointerLockElement);
else {
console.log("The pointer is not locked");
}
});
Using the onpointerlockchange event handler property (but note that this replaces other event listeners added using onpointerlockchange, if any):
document.onpointerlockchange = (event) => {
if (document.pointerLockElement)
console.log("The pointer is locked to: ", document.pointerLockElement);
else {
console.log("The pointer is not locked");
}
};