PointerEvent

Class

Common
expect class PointerEvent
internal constructor(
    changes: List<PointerInputChange>,
    internalPointerEvent: InternalPointerEvent?,
)

Describes a pointer input change event that has occurred at a particular point in time.

Secondary Constructors

constructor(changes: List<PointerInputChange>)

Parameters

changesThe changes.

Properties

Common
val changes: List<PointerInputChange>

The changes.

Common
val buttons: PointerButtons

The state of buttons (e.g. mouse or stylus buttons) during this event.

Common
val keyboardModifiers: PointerKeyboardModifiers

The state of modifier keys during this event.

Common
var type: PointerEventType

The primary reason the PointerEvent was sent.

Android
actual class PointerEvent
internal actual constructor(
    /** The changes. */
    actual val changes: List<PointerInputChange>,
    internal val internalPointerEvent: InternalPointerEvent?,
)

Describes a pointer input change event that has occurred at a particular point in time.

Secondary Constructors

actual constructor(changes: List<PointerInputChange>) : this(changes, null)

Parameters

changesThe changes.

Properties

Android
val motionEvent: MotionEvent?

The underlying Android MotionEvent that triggered this PointerEvent.

This property provides access to the raw MotionEvent for retrieving platform-specific information not yet exposed by the Compose PointerEvent API (e.g., stylus tilt angle).

Important Considerations:

  1. Read-Only: The returned MotionEvent is strictly read-only. Modifying it will lead to unpredictable behavior.
  2. Transient: Do not store a reference to this MotionEvent. The Android framework may recycle it, rendering its state undefined and causing errors if accessed later. Access the data only within the scope where the PointerEvent is received.
  3. Metadata Only: This MotionEvent should not be used for primary input handling logic (e.g., determining pointer position or button presses). Rely on the properties of PointerEvent and PointerInputChange for this purpose. The MotionEvent is intended solely for accessing supplemental metadata.
  4. Nullability: This property will be null in two cases: * The PointerEvent was fabricated within Compose (i.e., not directly from a system input event). * The PointerEvent has already been dispatched within the Compose input system. (See androidx.compose.ui.samples.PointerEventMotionEventSample for details).
Android
@get:MotionEventClassification
val classification: Int

Returns ``MotionEvent's classification(https://developer.android.com/reference/android/view/MotionEvent#getClassification()).

Android
actual val buttons = PointerButtons(motionEvent?.buttonState ?: 0)
Android
actual val keyboardModifiers = PointerKeyboardModifiers(motionEvent?.metaState ?: 0)
Android
actual var type: PointerEventType

Functions

fun component1(): List<PointerInputChange>
fun copy(changes: List<PointerInputChange>, motionEvent: MotionEvent?): PointerEvent