Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Read Pointer?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/blit386-read-pointer)
---
name: read-pointer
description:
Read mouse, touch, and pen input through BLIT386's unified pointer API with up to four slots. Use for clicking,
dragging, painting, aiming, scrolling, or touch controls.
---
# Read the mouse, touch, and pen
Mouse, touch, and pen share one "pointer" API with up to four slots. Slot 0 is the mouse or first touch.
## How to do it
```js
configure() {
return {
// Needed so BT.pointerScrollDelta works and the page does not scroll over the canvas.
isCapturingPointerScroll: true,
};
}
update() {
if (BT.isPointerActive(0)) {
const p = BT.pointerPos(0); // a Vector2i in screen pixels
const move = BT.pointerDelta(0); // how far it moved since the last update()
if (BT.isDown(BT.BTN_POINTER_A, 0)) this.paintAt(p); // primary button held
if (BT.isPressed(BT.BTN_POINTER_A, 0)) this.startDrag(p);
if (BT.isReleased(BT.BTN_POINTER_A, 0)) this.endDrag(p, move); // move as flick velocity
}
const wheel = BT.pointerScrollDelta; // a getter; vertical wheel movement since the last update() (pixels)
this.zoom += wheel;
}
```
## Key calls
- `BT.pointerPos(slot?)` / `BT.pointerDelta(slot?)` - methods, return `Vector2i`.
- `BT.pointerPosTo(out, slot?)` / `BT.pointerDeltaTo(out, slot?)` - methods, engine 1.7.0+; write into an existing
`Vector2i` and return it, instead of making a new one. The destination comes first. Reach for these only inside a hot
loop - see the `keep-it-fast` skill.
- `BT.isPointerActive(slot?)` - method; is a pointer present in that slot.
- `BT.nativeScreenToDisplayPos(clientX, clientY)` - method, engine 1.8.0+; converts a DOM event's `clientX` / `clientY`
to display pixels, or `null` before init or for a zero-size canvas. Only for DOM events the engine does not wrap, such
as a file dropped on the canvas - for the mouse and touch, `pointerPos` already is in display pixels.
- `BT.pointerScrollDelta` - getter; vertical wheel delta since the last `update()` when read there (requires
`isCapturingPointerScroll: true`).
- Buttons: `BT.BTN_POINTER_A` (primary), `BTN_POINTER_B/C/D`, `BTN_POINTER_ANY`, used with
`BT.isDown/isPressed/isReleased`.
- `BT.hideCursor()` / `BT.showCursor()` - methods; hide or restore the OS cursor over the canvas.
## Notes
- Slots: 0 = mouse or first touch; 1-3 = extra touches or pens (multi-touch).
- Read in `update()`. Positions are already in your screen's pixel coordinates. A click, release, drag, or wheel turn
that lands on a fast display between two `update()` steps waits for the next one, and a click counts once even when
one frame runs several updates (engine 1.9.0+) - there is nothing to work around.
- A click or tap that goes down and up between two `update()` steps (Playwright `page.mouse.click()` with no `delay`, a
fast trackpad tap) is not lost (engine 1.9.0+): that one `update()` sees `BT.isPressed` and `BT.isReleased` both true,
and `BT.isDown` already false. On 1.9.0+ a play-test click needs no `delay`; on engine 1.8.0 hold the button for about
100 ms or the click is lost. Two clicks inside one `update()` step count as one, so wait a step between them.
- A touch tap lives in slots 1-3 and frees its slot on release, so `isPointerActive(slot)` is already false on the
`update()` that sees a quick tap. Read its edges without that guard; `pointerPos(slot)` still holds the last position:
```js
for (let slot = 1; slot < 4; slot++) {
if (BT.isPressed(BT.BTN_POINTER_A, slot)) this.startDrag(BT.pointerPos(slot));
if (BT.isReleased(BT.BTN_POINTER_A, slot)) this.endDrag(BT.pointerPos(slot), BT.pointerDelta(slot));
}
```
- `pointerDelta` read in `update()` is the movement since the previous `update()`, so it makes a good drag velocity: on
the `BT.isReleased(BT.BTN_POINTER_A)` tick, use it as the "flick" speed. It matches on 60 Hz and 120 Hz screens.
- Wheel capture is opt-in: set `isCapturingPointerScroll: true` in `configure()` when you map the mouse wheel. Without
it the host page scrolls normally and `BT.pointerScrollDelta` stays `0`.
- The same flag gates touch scrolling past the canvas: off means `touch-action: pan-y` (phones can tap-hold-scroll the
page); on means `touch-action: none` so the game owns the gesture.
See `docs/input.md`.