msgProc: Mouse Messages

Complete reference for all mouse-related msgProc events. Covers button presses, movement, wheel scrolling, and enter/leave tracking.

Left Button Down (MSG_LBUTTONDOWN)

MSG_LBUTTONDOWN fires when the left mouse button is pressed. Use this to start drag operations, track the beginning of mouse interactions, or implement custom click handling. This event fires before MSG_LCLICK.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Left Button Up (MSG_LBUTTONUP)

MSG_LBUTTONUP fires when the left mouse button is released. Use this to finalize mouse interactions, complete operations started in MSG_LBUTTONDOWN, or release mouse capture. This event fires before MSG_LCLICK.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Right Button Down (MSG_RBUTTONDOWN)

MSG_RBUTTONDOWN fires when the right mouse button is pressed. Use this to detect the start of right-click actions or custom context menu positioning.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Right Button Up (MSG_RBUTTONUP)

MSG_RBUTTONUP fires when the right mouse button is released. This event fires before MSG_RCLICK and any gesture recognition. Use this to detect the end of right-button interactions.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Middle Button Down (MSG_MBUTTONDOWN)

MSG_MBUTTONDOWN fires when the middle mouse button (typically mouse wheel button) is pressed. Use this to implement panning, custom middle-click actions, or alternative interaction modes.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Middle Button Up (MSG_MBUTTONUP)

MSG_MBUTTONUP fires when the middle mouse button is released. Use this to finalize middle-button interactions like panning or custom gestures.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Left Click (MSG_LCLICK)

MSG_LCLICK fires when the left mouse button is clicked - pressed and released without significant movement. This high-level click event fires after MSG_LBUTTONDOWN and MSG_LBUTTONUP. Use this for simple click handling when you don't need to track the button down/up sequence separately.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Left Double Click (MSG_LDBLCLICK)

MSG_LDBLCLICK fires when the left mouse button is double-clicked. The timing threshold is determined by browser/OS double-click speed settings. Use this to implement edit modes, expand/collapse actions, or other double-click behaviors.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Right Click (MSG_RCLICK)

MSG_RCLICK fires when the right mouse button is clicked - pressed and released without gesture movement. Use this for context menus.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Middle Click (MSG_MCLICK)

MSG_MCLICK fires when the middle mouse button is clicked - pressed and released. Use this for alternative actions like opening links in new tabs or toggling modes.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Mouse Move (MSG_MOUSEMOVE)

MSG_MOUSEMOVE fires when the mouse pointer moves within container boundaries (or anywhere during mouse capture). Events are throttled to 60 FPS by default to balance responsiveness with performance. Use this to track mouse position, update cursor feedback, or implement drag operations.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()
Throttling: Mouse move events are throttled to 60 FPS by default. Change with wakaPAC.mouseMoveThrottleFps before initialization. Set to 0 to disable throttling, or increase to values like 120 for higher precision tracking.

Mouse Enter (MSG_MOUSEENTER)

MSG_MOUSEENTER fires when the mouse pointer enters a container's boundary. Use this to implement hover states, show tooltips, or provide visual feedback. This tracks logical container boundaries, not individual DOM elements, providing clean state transitions.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()
Capture Behavior: MSG_MOUSEENTER and MSG_MOUSELEAVE are suppressed during mouse capture. The captured container logically retains the pointer even if the cursor physically moves outside its boundaries. See Mouse Capture for details.

Mouse Leave (MSG_MOUSELEAVE)

MSG_MOUSELEAVE fires when the mouse pointer leaves a container's boundary. Use this to clear hover states, hide tooltips, or reset visual feedback. Paired with MSG_MOUSEENTER, these events provide desktop-style hover semantics.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Mouse Enter Descendant (MSG_MOUSEENTER_DESCENDANT)

MSG_MOUSEENTER_DESCENDANT fires when the mouse pointer enters an interactive child element within a container. This provides desktop-style child control hover tracking — only elements that would be considered "controls" trigger this event, not plain text or layout wrappers. An element is considered interactive if it is a native form/link element (INPUT, BUTTON, SELECT, TEXTAREA, A, LABEL, DETAILS, SUMMARY), has a data-pac-hoverable attribute, or has a tabindex. Use this to implement per-control hover highlights, show control-specific tooltips, or provide visual feedback on individual elements within a container.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()
Capture Behavior: MSG_MOUSEENTER_DESCENDANT is suppressed during mouse capture, just like MSG_MOUSEENTER and MSG_MOUSELEAVE. See Mouse Capture for details.

Mouse Leave Descendant (MSG_MOUSELEAVE_DESCENDANT)

MSG_MOUSELEAVE_DESCENDANT fires when the mouse pointer leaves an interactive child element within a container, either by moving to another child, to the container's own background, or out of the container entirely. Paired with MSG_MOUSEENTER_DESCENDANT, these events provide desktop-style child control hover semantics. Use this to clear per-control hover states, hide control-specific tooltips, or reset visual feedback on individual elements.

Message Parameters

Parameter Type Description
wParam number Modifier key and button state flags: MK_SHIFT, MK_CONTROL, MK_ALT, MK_RBUTTON, MK_MBUTTON
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Example: Per-Control Hover Highlight

msgProc(event) {
    if (event.message === wakaPAC.MSG_MOUSEENTER_DESCENDANT) {
        event.target.classList.add('hover');
    }

    if (event.message === wakaPAC.MSG_MOUSELEAVE_DESCENDANT) {
        event.target.classList.remove('hover');
    }
}

Mouse Wheel (MSG_MOUSEWHEEL)

MSG_MOUSEWHEEL fires when the user scrolls the mouse wheel (vertical scrolling only). Use this to implement custom scrolling, zooming, or value adjustment. Wheel events respect mouse capture and route to the captured container when active.

Message Parameters

Parameter Type Description
wParam number High word (HIWORD) = wheel delta (±120 per notch, positive = scroll up, negative = scroll down). Low word (LOWORD) = modifier key flags (MK_SHIFT, MK_CONTROL, MK_ALT)
lParam number Packed coordinates: low 16 bits = x coordinate, high 16 bits = y coordinate (relative to container). Extract using MAKEPOINTS(), LOWORD(), or HIWORD()

Detail Properties

Property Type Description
wheelDelta number Raw vertical scroll delta from browser (positive = scroll up, negative = scroll down). Use for pixel-perfect scrolling control
wheelDeltaX number Raw horizontal scroll delta from browser (for custom horizontal scrolling support)
deltaMode number Units of the delta value: 0 = pixels (touchpad), 1 = lines (mouse wheel), 2 = pages (rare)

Helper Functions

const delta = wakaPAC.GET_WHEEL_DELTA(event.wParam);  // ±120 per notch (normalized)
const modifiers = wakaPAC.GET_KEYSTATE(event.wParam); // Modifier key flags

Example: Zoom Control

msgProc(event) {
    if (event.message === wakaPAC.MSG_MOUSEWHEEL) {
        const delta = wakaPAC.GET_WHEEL_DELTA(event.wParam);
        const modifiers = wakaPAC.GET_KEYSTATE(event.wParam);
        const pos = wakaPAC.MAKEPOINTS(event.lParam);

        // Ctrl+Wheel = zoom
        if (modifiers & wakaPAC.MK_CONTROL) {
            this.zoom += (delta > 0) ? 0.1 : -0.1;
            return false;  // Prevent page scrolling
        }

        // Normal wheel = scroll (allow default behavior)
        return true;
    }
}
Scroll Prevention: Return false from msgProc to prevent default page scrolling when handling wheel events. Return true to allow normal browser scrolling behavior.
Delta Normalization: The wheel delta in lParam is normalized to ±120 per notch (desktop-style standard), regardless of browser or device. Use event.detail.wheelDelta for the raw browser delta value if you need pixel-perfect scrolling control.

Best Practices

  • Use MAKEPOINTS for coordinates: Always extract coordinates with wakaPAC.MAKEPOINTS(event.wParam) for clean, readable code
  • Store positions privately: Use underscore-prefixed properties like _dragStartX to avoid triggering reactivity during tracking
  • Return false appropriately: Return false when you handle an event to prevent standard bindings and browser defaults
  • Check button state in wParam: Use event.lParam & wakaPAC.MK_LBUTTON to check if left button is held during mousemove
  • Use capture for drag operations: Call wakaPAC.setCapture() on LBUTTONDOWN to ensure continuous tracking. See Mouse Capture
  • Clean up on button up: Release capture and clear tracking state in MSG_LBUTTONUP handlers
  • Consider throttling: Adjust wakaPAC.mouseMoveThrottleFps based on your performance needs
  • Mark custom controls as hoverable: Add data-pac-hoverable or tabindex to non-standard interactive elements (styled divs, custom components) to enable descendant hover tracking