/dm-game:pointer-lockfrom dm-game
Pointer lock in a browser game: deriving whether the mouse should be captured every frame from named unlock reasons (a menu, a map, a debug pane, a player preference), requesting it from a user gesture or right after the game's own release, Chrome's 1250 ms refusal after the player escapes a lock, retrying while the click's activation is still live, reporting a lost lock to the pause latch, giving back a lock granted too late, falling back when raw input is unsupported, locking before fullscreen, virtual cursors, a fallback look mode when lock is denied, and where the reticle should read from. Use when adding mouse-look or mouse aiming, when menus open over a locked pointer, or when players report 'the mouse won't recapture after the menu', 'clicking does nothing for a second', 'I pressed Esc and the game kept running', 'the cursor is stuck in the window', or 'the reticle jitters'. game-shell owns pausing; this skill owns the lock.
Ships in dm-game. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Purpose: The mouse is captured exactly when play wants it, and released for every menu. It comes back on the next click, and a lost lock never leaves the game running with an invisible cursor.
Sources:
Element.requestPointerLock():
pointerlockerrorexitPointerLock() exempts the next requestunadjustedMovement may reject with NotSupportedErrorrequestFullscreen(), because fullscreen consumes the
activationchrome/browser/ui/exclusive_access/pointer_lock_controller.cc,
kEffectiveUserEscapeDuration = base::Milliseconds(1250), on main as of
2026-10-11. Chrome refuses a lock request for 1250 ms after the player escapes
one (posture A). Other browsers: unknown, so posture B.navigator.userActivation.isActive reports it.Typed sketch: references/pointer-lock.ts. Its state machine was tested
against a stubbed DOM covering:
NotSupportedErrorThe tests were mutation-checked on the in-flight guard.
| Failure | Seen in | Root cause |
|---|---|---|
| Lock never comes back after a modal | the reason this skill exists (operator brief) | A single request after closing a menu falls inside the cooldown, or has no activation, and is never retried |
| Our own release reported as a loss, so pause opens behind a closing menu | redshifted (fixed 0db70d39) | want cleared after exitPointerLock() |
| Lock granted after the player opened a menu | redshifted (no give-back) | A late-resolving request is kept |
| Retry comment claims a timer that doesn't exist | abduction-run (read from code) | Lock returns only on a canvas click or a state change |
| Esc unlocks, and the sim keeps running | redshifted (no blur pause; lock loss was the only trigger) | Lock loss not wired to one pause latch |
exitPointerLock() fails with pointerlockerror (probe page, the operator,
2026-10-12). There, resuming from a key shows "Click to aim" too. Chrome 154
honours it: the same request, 6 s after the release with activation expired,
got the lock. Safari is unprobed (its run was spoiled by extra clicks).want every frame, from named reasonswant = baseline && reasons.size === 0
// baseline: in play, the "Capture mouse" option on, input is mouse (not touch)
// reasons: 'screen' (shell.ownsInput), 'map', 'debug', 'preview', ...
Each owner adds and removes its own reason. Abduction-run's set includes overlay,
debugPane, worldMap, characterPreview, briefing and userPreference. Nothing calls
requestPointerLock() or exitPointerLock() directly except the lock module.
game-shell's onStackChange sets or clears 'screen'.
When want becomes false:
wanted = falseexitPointerLock()Then the pointerlockchange that follows is known to be ours and is never reported
as a loss (Hard Deck, redshifted 0db70d39). Per the spec, a programmatic exit also
exempts the next request from the post-Esc rule, so menus the game opened can
relock instantly where the browser honours it (Chrome 154 does, Firefox 150
doesn't; rule 3).
want becomes true, request once, whatever the context.
exitPointerLock(), the spec exempts the next request
from needing activation, so a menu the game opened can relock on resume with no
click. Firefox 150 refuses that request; the try costs nothing, and its refusal
falls through to the activation check and "Click to aim".requestPointerLock() returns no promise. Failure arrives
only as pointerlockerror, so listen for the event as well as the rejection
(the sketch does both).onGesture()
synchronously: a canvas click, a Resume click, Enter or Space on Resume. That
call makes the request inside the activation.'screen' reason, once by onGesture().
Raw-input fallback follows rule 6.navigator.userActivation.isActive
is true.
pointerlockerror on its own: schedule the next retry or show the
prompt. Hard Deck and abduction-run route it into the change handler.pointerlockchange to unlocked while wanted: Esc, focus
leaving, or the OS taking the pointer.shell.requestAutoPause('lockLost') once the lock had been
held for a grace period. A loss inside the grace doesn't pause, but it isn't
ignored either: it shows "Click to aim".
LOCK_GRACE_MS); B for yours. Test:
acquire-then-immediately-lose on resume doesn't open a stray pause. If it does,
lengthen the grace.suspended latch has
the same intent: a loss means pause, not a silent relock.pointerlockchange in the same millisecond. Chrome 154 and Firefox 150 don't
deliver it at all (probe page, run by the operator 2026-10-12). game-shell's Esc grace makes
either ordering safe.NotAllowedError even with activation live, and a
click ~1.23 s later succeeded. Its refusal window between those two is
unmeasured. Chrome's is the 1250 ms above.A request that resolves after want went false (the player opened a menu
mid-request) arrives as a lock nobody wants. On a pointerlockchange to locked
with !wanted, call exitPointerLock() at once (Hard Deck).
{ unadjustedMovement: true } first. It turns off OS mouse
acceleration.
NotSupportedError, drop it for the session.NotAllowedError, or SecurityError, which is how
Chrome 154 reports its post-Esc cooldown (probe page, 2026-10-12: refused at
1163 ms, granted at 1328 ms). That is Hard Deck's per-request fallback. An engine that rejects
the option with an odd error still locks, and a transient error doesn't cost
raw input for good.NotSupportedError. Some older engines
throw synchronously, so wrap the request in an async function.pointerType on the gesture (Hard Deck).movementX/movementY and clamps to the
viewport, scaled by the sensitivity setting (abduction-run virtualCursor.ts).When lock is unavailable (the option is off, the request failed, or the platform can't do it):
main.ts)The game must remain playable.
pointerover while locked (menu-navigation). In practice an open screen has
already released the lock.exitPointerLock
itself must instead add a reason, or it fights the derivation every frame.allow-pointer-lock sandbox token, or every request fails and the fallback mode
is all the player gets. Check the live embed once, rather than assuming the host
sets it.Each line names what the check cannot see.
Unit, the want derivation: for each reason, want is false while it's
set, and returns when it clears. Blind to: browser behaviour.
Real browser, real input (CDP, not synthetic events): - click to lock, press Esc: pause opens once, and the cursor is visible - click Resume within 1 s: lock returns once the cooldown passes, without a second click - after escaping the lock, resume with Esc: "Click to aim" shows, and a click relocks - open pause with P, then resume with Esc: the lock returns with no click (in Firefox 150, "Click to aim" instead)
*Blind to: browsers other than the one tested. Run once in Firefox and
Safari by hand.*
Open Options from a key during play: the lock releases, the release isn't reported as a loss, and on close it relocks with no click (programmatic-exit exemption; Firefox 150 shows "Click to aim" instead).
Alt-tab while locked: the game pauses, and the lock isn't restored on return until the player clicks. Blind to: OS-specific focus behaviour.
Deny lock (option off, or an iframe without allow-pointer-lock): the
fallback mode works and the notice shows once.
Reticle at 120 Hz or more: it moves smoothly. A world-anchored marker doesn't step. Blind to: 60 Hz screens, where stepping is invisible. Test on a high-refresh display.
Three tight links. Everything else routes through the map, so adding a skill
touches one file rather than twenty: references/routing-map.md (in
game-design).
onStackChange for the 'screen' reasonWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub rbergman/dark-matter-marketplace --plugin dm-game40 skills in this plugin
/accessibility-designUse when designing any player-facing feature, evaluating a game for accessibility, responding to accessibility feedback, designing difficulty or assist options, adding subtitle/caption systems, implementing input remapping, or when a player reports they can't play. Covers the four accessibility pillars (visual, auditory, motor, cognitive), implementation tiers, colorblind design, subtitle standards, input accessibility, and testing methodology. Accessibility is a design discipline, not a post-launch checklist./async-and-socialSocial and competitive design that does not require players to be online together: ghost/replay data, leaderboards, asynchronous PvP, offline vulnerability, and anti-snowball mechanics. Use when adding leaderboards or high-score tables, designing ghost races or replay challenges, letting players attack or compete against absent opponents, deciding what social signal a single-player game should carry, or when matches and runs feel decided in the first minutes. Anti-snowball applies to single-player roguelikes and simulations too, not just PvP. For real-time multiplayer architecture, matchmaking, guilds, and moderation, this skill deliberately does not cover them — those are large specialities and belong in dedicated references./audio-designUse when designing how audio communicates game state, creates emotion, and serves as a feedback system. Activate for sound effect design, adaptive music systems, spatial audio, ambient soundscapes, audio priority and ducking, emotional audio design, and audio accessibility. Also activate when audio feels disconnected from gameplay, when players routinely play on mute (a design failure signal), when evaluating whether the audio stack has appropriate layering and variation, or when planning how music responds to gameplay context. This skill treats audio as a design system — not audio engineering or production, but the intentional design of what players hear, when, and why. Covers the full audio stack from music and ambience through sound effects, UI audio, and voice./camera-controlControlling a 2D or top-down game camera, not juicing it: a pure 'where it wants to be' target kept separate from 'how it gets there'; exponential damping versus a critically damped spring, with halflife as the tuning unit; velocity look-ahead and an aim lead on its own slow clock; zoom as a product of named factors (player base zoom, wheel, screen size, speed); combat framing that zooms out to keep every threat on screen, with a floor; an optional rotate-with-ship (heading-follow) mode and what it does to the HUD; shake applied only at render and never to the aim; one pair of world/screen conversions; and the camera options players expect. Use when building or reviewing a follow camera, adding zoom or a camera options tab, or when players say 'the view jumped when my mouse came back', 'I got shot from off screen', 'I can't see far enough ahead', 'the zoom makes me sick', 'it's too floaty' or 'too stiff', or 'the arrow points the wrong way'. Shake, punch and the trauma budget are game-feel's./cosmic-horror-registerTone, diction, and sensory palette for cosmic-horror game narrative — Lovecraftian, weird-fiction, eldritch, Arkham-adjacent, deep-time or deep-space dread. Use when writing or reviewing in-game text, story bibles, item descriptions, or interstitials for a cosmic-horror game; when horror prose reads as generic spooky rather than cosmic; when the mystery is being over-explained; or when a draft is leaning on words like eldritch, unspeakable, or indescribable to do the work. Also the worked example of the six-slot register template — read the Register template section to build folk-horror, noir, comic, or any other tonal register the same way. Layers on top of game-narrative-craft, which supplies the structural rules; this skill supplies only tone./data-driven-designTelemetry and analytics for games: event taxonomy and schema, engagement/progression/economy/balance/UX metrics, funnel analysis, A/B testing and when not to, cohort analysis, dashboard design, and the interpretation traps — Goodhart's Law, Simpson's paradox, survivorship bias, over-optimisation. Use when instrumenting a game, deciding what to measure, reading a retention or funnel drop, comparing cohorts, or when a metric moved and you need to know whether it means anything. Data-informed, not data-driven: numbers say what happened, not why. For pre-ship qualitative evidence use playtest-design.