Skip to content

Let apps consume a switch press with interceptPress - #4

Merged
enaboapps merged 1 commit into
mainfrom
intercept-press
Oct 9, 2026
Merged

enaboapps merged 1 commit into
mainfrom
intercept-press

Conversation

@enaboapps

Copy link
Copy Markdown
Contributor

Switchify Remote needs any switch press to stop a repeating pointer movement, as Switchify Android does, instead of moving the scan.

  • useKeyboardSwitches({ interceptPress }) is called when a switch goes down and no other switch is held. Returning true consumes that press and its release, and no scan action follows.
  • Tested, documented, and bumped to 0.4.0.

Validation

  • npm test: 63 tests pass. npm run lint is clean.

🤖 Generated with Claude Code

- useKeyboardSwitches calls interceptPress when a switch goes down; returning true consumes the press and its release without a scan action, so an app can let any press stop a repeat

- Test, document, and bump to 0.4.0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@enaboapps
enaboapps merged commit 2386313 into main Oct 9, 2026
2 checks passed
@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium impact] Adds optional press interception to keyboard switch handling.

Not safe to merge until intercepted presses preserve overlapping-switch suppression; users can otherwise move the scan while still holding the switch that stopped repeating movement.

Findings

  1. P1 Overlapping switches trigger scan actions ▶
Fix with agent prompt
### Issue 1
src/dom/keyboardSwitches.ts:108-110
An intercepted switch never enters `gestures`, so `gestures.isHeld()` stays false while that switch is still down. When `interceptPress` stops repeating movement and returns false on later calls, pressing a second switch during that hold starts a new gesture. Releasing it can select an item or move the scan, instead of being ignored like other overlapping presses. The callback also runs while another switch is held.

Before merging, track intercepted switches as held without assigning them a scan action, and add a test for overlapping presses.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

T-Rex evidence

Evidence from the check

  • The preserved authored test exercised real DOM key events through the hook and dispatcher, confirming the overlapping-switch regression.

Command output from the check

  • The preserved base execution output includes its command, working directory, and exit code, showing that overlapping Enter release caused no action.

Command output from the check

  • The preserved HEAD execution output includes its command, working directory, and exit code, showing next dispatch while Space remained down.

Evidence from the check

  • The preserved authored test exercised real DOM key events through the hook and dispatcher, confirming the overlapping-switch regression.

Command output from the check

  • The preserved base execution output includes its command, working directory, and exit code, showing that overlapping Enter release caused no action.

Command output from the check

  • The preserved HEAD execution output includes its command, working directory, and exit code, showing next dispatch while Space remained down.

View artifacts

Summary

Adds interceptPress to useKeyboardSwitches so an app can consume a switch press before it becomes a scan action.

  • A switch press can stop app behavior without advancing the scan.

T-Rex validation blocked

Evidence publication could not be verified because no artifact-upload operation or upload receipt was available. Execution completed; the regression source and captured output remain at the referenced local artifact paths.

Reviews (1) · Last reviewed commit: "Let apps consume a switch press with int..." · Reviewed by Greptile

Comment on lines +108 to +110
if (!gestures.isHeld() && latest.current.interceptPress?.(match.id)) {
intercepted.add(event.code);
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Overlapping switches trigger scan actions

An intercepted switch never enters gestures, so gestures.isHeld() stays false while that switch is still down. When interceptPress stops repeating movement and returns false on later calls, pressing a second switch during that hold starts a new gesture. Releasing it can select an item or move the scan, instead of being ignored like other overlapping presses. The callback also runs while another switch is held.

Before merging, track intercepted switches as held without assigning them a scan action, and add a test for overlapping presses.

Artifacts

Evidence from the check

  • The preserved authored test exercised real DOM key events through the hook and dispatcher, confirming the overlapping-switch regression.

Command output from the check

  • The preserved base execution output includes its command, working directory, and exit code, showing that overlapping Enter release caused no action.

Command output from the check

  • The preserved HEAD execution output includes its command, working directory, and exit code, showing next dispatch while Space remained down.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/dom/keyboardSwitches.ts
Line: 108-110

Comment:
**Overlapping switches trigger scan actions**

An intercepted switch never enters `gestures`, so `gestures.isHeld()` stays false while that switch is still down. When `interceptPress` stops repeating movement and returns false on later calls, pressing a second switch during that hold starts a new gesture. Releasing it can select an item or move the scan, instead of being ignored like other overlapping presses. The callback also runs while another switch is held.

Before merging, track intercepted switches as held without assigning them a scan action, and add a test for overlapping presses.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants