Skip to content

feat(keyboard): hold modifiers for keyboard and mouse input inside a block - #655

Merged
route merged 1 commit into
mainfrom
fix/keyboard-modifier-down-up
Oct 18, 2026
Merged

route merged 1 commit into
mainfrom
fix/keyboard-modifier-down-up

Conversation

@route

@route route commented Oct 18, 2026

Copy link
Copy Markdown
Member

Fixes #581

Chrome doesn't carry a pressed modifier over to later input events: each CDP event needs its own modifiers, so a shift+drag required raw Input.dispatchMouseEvent calls.

page.keyboard.hold(:shift) do
  page.mouse.move(x: 10, y: 10).down.move(x: 200, y: 200, steps: 10).up
end
  • Keyboard#hold(*modifiers) { } presses the modifiers, makes every keyboard and mouse event in the block carry them and releases them when the block returns or raises. Nested blocks press a key once, and a release failure after the block raised doesn't hide the original error. State lives only for the block, so a missing keyup can't leak into later input.
  • Typing respects held keys: hold(:shift) { type("abc") } types ABC, holding Cmd/Ctrl and typing a selects all.
  • Mouse#move accepts modifiers: like down and up. An explicit value overrides the held keys for that event.
  • Mouse#click(modifiers:) now sends the modifiers with its mousemove too.
  • Keyboard#down/#up raise ArgumentError for a modifier and point to hold. down(:shift) used to crash with NoMethodError and up(:shift) sent an empty keyup event.

…block

Chrome doesn't carry a pressed modifier over to later input events, so a shift+drag needed raw CDP commands. Keyboard#hold
presses the given modifiers, makes every keyboard and mouse event in the block carry them and releases them when the block
returns or raises. State lives only for the block, so a missing keyup can't leak into later input.

Keyboard#down and #up raise ArgumentError for a modifier and point to hold: down used to crash with NoMethodError and up
sent an empty keyup event. Mouse#move accepts modifiers: like down and up, and Mouse#click sends its modifiers with the
preceding mousemove too.

Refs #581.
@route
route merged commit 5d4a0d7 into main Oct 18, 2026
7 checks passed
@route
route deleted the fix/keyboard-modifier-down-up branch October 18, 2026 16:49
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.

Modifer keys for mouse movement

1 participant