Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class PointerEvent
- Object
- PointerEvent
Immutable snapshot describing the rich detail of a pointer interaction that goes beyond the simple x/y coordinates carried by the legacy pointer callbacks.
A PointerEvent exposes which mouse button triggered the interaction, the kind of
pointing device used (finger, mouse, stylus or eraser), the pressure applied, stylus
tilt, the size of the contact area and the keyboard modifiers that were held down.
The snapshot is available in two ways:
- From an
ActionEventfired by a pointer listener viaActionEvent#getPointerEvent(). - By polling
com.codename1.ui.Display#getCurrentPointerEvent()(or the matchingcom.codename1.ui.CNconvenience method) while a pointer event is being dispatched.
Every value carries a safe default so code written against the rich API behaves predictably
on devices and ports that do not supply the extra detail. On such ports the button defaults to
BUTTON_PRIMARY, the pressure to 1.0, the type to TYPE_UNKNOWN and tilt/contact size to 0.
Fields
public static final int TYPE_UNKNOWN = 0 | The pointing device could not be determined. |
public static final int TYPE_TOUCH = 1 | The interaction came from a finger on a touch screen. |
public static final int TYPE_MOUSE = 2 | The interaction came from a mouse or trackpad. |
public static final int TYPE_STYLUS = 3 | The interaction came from a stylus or pen (Apple Pencil, S-Pen, Surface Pen and similar). |
public static final int TYPE_ERASER = 4 | The interaction came from the eraser end of a stylus. |
public static final int BUTTON_NONE = -1 | No button is associated with this event (for example a hover or a plain touch). |
public static final int BUTTON_PRIMARY = 0 | The primary (usually left) mouse button, or a plain touch/stylus contact. |
public static final int BUTTON_SECONDARY = 1 | The secondary (usually right) mouse button or stylus barrel button. |
public static final int BUTTON_MIDDLE = 2 | The middle mouse button (often the scroll wheel click). |
public static final int BUTTON_BACK = 3 | The back (fourth) mouse button. |
public static final int BUTTON_FORWARD = 4 | The forward (fifth) mouse button. |
public static final int MASK_PRIMARY = 1 | Button mask bit for the primary button. |
public static final int MASK_SECONDARY = 2 | Button mask bit for the secondary button. |
public static final int MASK_MIDDLE = 4 | Button mask bit for the middle button. |
public static final int MASK_BACK = 8 | Button mask bit for the back button. |
public static final int MASK_FORWARD = 16 | Button mask bit for the forward button. |
public static final int MODIFIER_SHIFT = 1 | Modifier mask bit indicating the shift key was held. |
public static final int MODIFIER_CONTROL = 2 | Modifier mask bit indicating the control key was held. |
public static final int MODIFIER_ALT = 4 | Modifier mask bit indicating the alt/option key was held. |
public static final int MODIFIER_META = 8 | Modifier mask bit indicating the meta/command/windows key was held. |
Constructors
public PointerEvent(int x, int y, int button, int buttonMask, int pointerType, float pressure, float tiltX, float tiltY, float contactSize, int modifiers, boolean hovering) | Creates a new immutable pointer event snapshot. |
Methods
public int getX() | The x position of the pointer in display pixels. |
public int getY() | The y position of the pointer in display pixels. |
public int getButton() | The button that triggered this event, one of the BUTTON_* constants. |
public int getButtonMask() | A bitmask of all buttons currently held down, built from the MASK_* constants. |
public int getPointerType() | The kind of pointing device that produced this event, one of the TYPE_* constants. |
public float getPressure() | The normalized pressure applied by the pointer between 0.0 and 1.0. |
public float getTiltX() | The stylus tilt across the x axis in degrees, or 0 when not reported. |
public float getTiltY() | The stylus tilt across the y axis in degrees, or 0 when not reported. |
public float getContactSize() | The normalized size of the contact area between 0.0 and 1.0, or 0 when not reported. |
public int getModifiers() | A bitmask of the keyboard modifiers held during this event, built from the MODIFIER_* constants. |
public boolean isHovering() | True if the pointer is hovering above the surface without making contact. |
public boolean isTouch() | True if this event came from a finger on a touch screen. |
public boolean isMouse() | True if this event came from a mouse or trackpad. |
public boolean isStylus() | True if this event came from a stylus or the eraser end of a stylus. |
public boolean isEraser() | True if this event came from the eraser end of a stylus. |
public boolean isPrimaryButton() | True if the triggering button is the primary (left) button. |
public boolean isSecondaryButton() | True if the triggering button is the secondary (right) button or stylus barrel button. |
public boolean isMiddleButton() | True if the triggering button is the middle button. |
public boolean isShiftDown() | True if the shift key was held during this event. |
public boolean isControlDown() | True if the control key was held during this event. |
public boolean isAltDown() | True if the alt/option key was held during this event. |
public boolean isMetaDown() | True if the meta/command/windows key was held during this event. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Field details
TYPE_UNKNOWN
public static final int TYPE_UNKNOWN = 0TYPE_TOUCH
public static final int TYPE_TOUCH = 1TYPE_MOUSE
public static final int TYPE_MOUSE = 2TYPE_STYLUS
public static final int TYPE_STYLUS = 3TYPE_ERASER
public static final int TYPE_ERASER = 4BUTTON_NONE
public static final int BUTTON_NONE = -1BUTTON_PRIMARY
public static final int BUTTON_PRIMARY = 0BUTTON_SECONDARY
public static final int BUTTON_SECONDARY = 1BUTTON_MIDDLE
public static final int BUTTON_MIDDLE = 2BUTTON_BACK
public static final int BUTTON_BACK = 3BUTTON_FORWARD
public static final int BUTTON_FORWARD = 4MASK_PRIMARY
public static final int MASK_PRIMARY = 1MASK_SECONDARY
public static final int MASK_SECONDARY = 2MASK_MIDDLE
public static final int MASK_MIDDLE = 4MASK_BACK
public static final int MASK_BACK = 8MASK_FORWARD
public static final int MASK_FORWARD = 16MODIFIER_SHIFT
public static final int MODIFIER_SHIFT = 1MODIFIER_CONTROL
public static final int MODIFIER_CONTROL = 2MODIFIER_ALT
public static final int MODIFIER_ALT = 4MODIFIER_META
public static final int MODIFIER_META = 8Constructor details
PointerEvent
public PointerEvent(int x, int y, int button, int buttonMask, int pointerType, float pressure, float tiltX, float tiltY, float contactSize, int modifiers, boolean hovering)Parameters
xint- the x position of the pointer in display pixels
yint- the y position of the pointer in display pixels
buttonint- one of the
BUTTON_*constants describing the triggering button buttonMaskint- bitmask of the
MASK_*constants describing all currently held buttons pointerTypeint- one of the
TYPE_*constants describing the pointing device pressurefloat- normalized pressure between
0.0and1.0, defaulting to1.0 tiltXfloat- stylus tilt across the x axis in degrees,
0when not available tiltYfloat- stylus tilt across the y axis in degrees,
0when not available contactSizefloat- normalized size of the contact area between
0.0and1.0 modifiersint- bitmask of the
MODIFIER_*constants describing held keyboard modifiers hoveringboolean- true if the pointer is hovering above the surface without contact
Method details
getX
public int getX()getY
public int getY()getButton
public int getButton()BUTTON_* constants. Defaults to
BUTTON_PRIMARY for plain touch interactions and BUTTON_NONE for hover events.getButtonMask
public int getButtonMask()MASK_* constants.getPointerType
public int getPointerType()TYPE_* constants.getPressure
public float getPressure()0.0 and 1.0. Ports that do not
report pressure return 1.0 so that pressure aware code keeps working.getTiltX
public float getTiltX()0 when not reported.getTiltY
public float getTiltY()0 when not reported.getContactSize
public float getContactSize()0.0 and 1.0, or 0 when not reported.getModifiers
public int getModifiers()MODIFIER_* constants.isHovering
public boolean isHovering()isTouch
public boolean isTouch()isMouse
public boolean isMouse()isStylus
public boolean isStylus()isEraser
public boolean isEraser()isPrimaryButton
public boolean isPrimaryButton()isSecondaryButton
public boolean isSecondaryButton()isMiddleButton
public boolean isMiddleButton()isShiftDown
public boolean isShiftDown()isControlDown
public boolean isControlDown()isAltDown
public boolean isAltDown()isMetaDown
public boolean isMetaDown()toString
public String toString()