Skip to Content
Input Handling

Input Handling — Mouse, Keyboard, and Touch Events

Foxbridge translates CDP input events to Juggler’s Page.dispatchMouseEvent, Page.dispatchKeyEvent, Page.dispatchTouchEvent, and Page.insertText methods. Each event type requires specific field mapping.

Mouse Events

Type Translation

CDP typeJuggler type
mouseMovedmousemove
mousePressedmousedown
mouseReleasedmouseup
mouseWheelwheel

Button Mapping

CDP sends button names as strings. Juggler expects numeric values:

CDP buttonJuggler button
"left"0
"middle"1
"right"2
"none"0

Buttons Bitmask

Juggler requires a buttons bitmask field on every mouse event. This indicates which buttons are currently held. The bitmask is only populated during mousedown:

ButtonBitmask value
Left1
Middle4
Right2

For mousemove, mouseup, and wheel events, buttons is always 0.

Additional Fields

FieldPassed throughNotes
x, yYesCoordinates in CSS pixels
clickCountYes1 for click, 2 for double-click
modifiersYesBitmask: Alt=1, Ctrl=2, Meta=4, Shift=8
deltaX, deltaYConditionalOnly included when non-zero (wheel events)

Keyboard Events

Type Translation

CDP typeJuggler type
keyDownkeydown
keyUpkeyup
rawKeyDownkeydown

The rawKeyDown mapping is the most important — CDP uses this for physical key presses, but Juggler only understands keydown. The translation uses strings.ToLower() with a special case for rawkeydown → keydown.

Field Mapping

CDP FieldJuggler FieldNotes
keykeyKey name (e.g., "a", "Enter")
codecodePhysical key (e.g., "KeyA", "Enter")
texttextCharacter generated (only if non-empty)
windowsVirtualKeyCodekeyCodeNumeric key code
modifiersNot forwarded (Juggler uses separate modifier keys)

Foxbridge also adds location: 0 and repeat: false as defaults, which Juggler requires.

Touch Events

ID Field Stripping

CDP includes an id field in each touch point to track individual fingers. Juggler rejects touch events that contain id. Foxbridge destructures each touch point and only forwards supported fields:

// CDP touch point (has id) {"id": 0, "x": 100, "y": 200, "radiusX": 1, "radiusY": 1, "force": 0.5} // Juggler touch point (no id) {"x": 100, "y": 200, "radiusX": 1, "radiusY": 1, "force": 0.5}

Optional fields (radiusX, radiusY, force) are only included when greater than zero. The modifiers bitmask is passed through unchanged.

insertText

Input.insertText maps directly to Page.insertText with no transformation. Used for characters that cannot be represented as key events (emoji, CJK).

Puppeteer Click Sequence

A page.click(selector) generates three events: mouseMoved (translated to mousemove), mousePressed (translated to mousedown with buttons: 1), and mouseReleased (translated to mouseup with buttons: 0).


See also

Last updated on