wxMouseEvent — wx v2.4.3

Search documentation of wx

# View Source wxMouseEvent (wx v2.4.3)

This event class contains information about the events generated by the mouse: they include mouse buttons press and release events and mouse move events.

All mouse events involving the buttons use `wxMOUSE_BTN_LEFT` for the left mouse button, `wxMOUSE_BTN_MIDDLE` for the middle one and `wxMOUSE_BTN_RIGHT` for the right one. And if the system supports more buttons, the `wxMOUSE_BTN_AUX1` and `wxMOUSE_BTN_AUX2` events can also be generated. Note that not all mice have even a middle button so a portable application should avoid relying on the events from it (but the right button click can be emulated using the left mouse button with the control key under Mac platforms with a single button mouse).

For the `wxEVT_ENTER_WINDOW` and `wxEVT_LEAVE_WINDOW` events purposes, the mouse is considered to be inside the window if it is in the window client area and not inside one of its children. In other words, the parent window receives `wxEVT_LEAVE_WINDOW` event not only when the mouse leaves the window entirely but also when it enters one of its children.

The position associated with a mouse event is expressed in the window coordinates of the window which generated the event, you can use `wxWindow:clientToScreen/3` to convert it to screen coordinates and possibly call `wxWindow:screenToClient/2` next to convert it to window coordinates of another window.

Note: Note the difference between methods like `leftDown/1` and the inherited `leftIsDown/1`: the former returns true when the event corresponds to the left mouse button click while the latter returns true if the left mouse button is currently being pressed. For example, when the user is dragging the mouse you can use `leftIsDown/1` to test whether the left mouse button is (still) depressed. Also, by convention, if `leftDown/1` returns true, `leftIsDown/1` will also return true in wxWidgets whatever the underlying GUI behaviour is (which is platform-dependent). The same applies, of course, to other mouse buttons as well.

See: `wxKeyEvent`

This class is derived, and can use functions, from:

- `wxEvent`

wxWidgets docs: wxMouseEvent

## Events

Use `wxEvtHandler:connect/3` with `wxMouseEventType` to subscribe to events of this type.

# Summary

## Types

wxMouse()
wxMouseEvent()
wxMouseEventType()

## Functions

altDown(This)

Returns true if the Alt key is pressed.

aux1DClick(This)

Returns true if the event was a first extra button double click.

aux1Down(This)

Returns true if the first extra button mouse button changed to down.

aux1Up(This)

Returns true if the first extra button mouse button changed to up.

aux2DClick(This)

Returns true if the event was a second extra button double click.

aux2Down(This)

Returns true if the second extra button mouse button changed to down.

aux2Up(This)

Returns true if the second extra button mouse button changed to up.

button(This, But)

Returns true if the event was generated by the specified button.

buttonDClick(This)

Equivalent to `buttonDClick(This, [])`.

buttonDClick/2

If the argument is omitted, this returns true if the event was a mouse double click event.

buttonDown(This)

Equivalent to `buttonDown(This, [])`.

buttonDown/2

If the argument is omitted, this returns true if the event was a mouse button down event.

buttonUp(This)

Equivalent to `buttonUp(This, [])`.

buttonUp/2

If the argument is omitted, this returns true if the event was a mouse button up event.

cmdDown(This)

Returns true if the key used for command accelerators is pressed.

controlDown(This)

Returns true if the Control key or Apple/Command key under macOS is pressed.

dragging(This)

Returns true if this was a dragging event (motion while a button is depressed).

entering(This)

Returns true if the mouse was entering the window.

getButton(This)

Returns the mouse button which generated this event or `wxMOUSE\_BTN\_NONE` if no button is involved (for mouse move, enter or leave event, for example).

getLinesPerAction(This)

Returns the configured number of lines (or whatever) to be scrolled per wheel action.

getLogicalPosition(This, Dc)

Returns the logical mouse position in pixels (i.e. translated according to the translation set for the DC, which usually indicates that the window has been scrolled).

getPosition(This)

Returns the physical mouse position.

getWheelAxis(This)

Gets the axis the wheel operation concerns.

getWheelDelta(This)

Get wheel delta, normally 120.

getWheelRotation(This)

Get wheel rotation, positive or negative indicates direction of rotation.

getX(This)

Returns X coordinate of the physical mouse event position.

getY(This)

Returns Y coordinate of the physical mouse event position.

isButton(This)

Returns true if the event was a mouse button event (not necessarily a button down event - that may be tested using `buttonDown/2`).

isPageScroll(This)

Returns true if the system has been setup to do page scrolling with the mouse wheel instead of line scrolling.

leaving(This)

Returns true if the mouse was leaving the window.

leftDClick(This)

Returns true if the event was a left double click.

leftDown(This)

Returns true if the left mouse button changed to down.

leftIsDown(This)

Returns true if the left mouse button is currently down.

leftUp(This)

Returns true if the left mouse button changed to up.

metaDown(This)

Returns true if the Meta key was down at the time of the event.

middleDClick(This)

Returns true if the event was a middle double click.

middleDown(This)

Returns true if the middle mouse button changed to down.

middleIsDown(This)

Returns true if the middle mouse button is currently down.

middleUp(This)

Returns true if the middle mouse button changed to up.

moving(This)

Returns true if this was a motion event and no mouse buttons were pressed.

rightDClick(This)

Returns true if the event was a right double click.

rightDown(This)

Returns true if the right mouse button changed to down.

rightIsDown(This)

Returns true if the right mouse button is currently down.

rightUp(This)

Returns true if the right mouse button changed to up.

shiftDown(This)

Returns true if the Shift key is pressed.

# Types

Link to this type

# wxMouse()

View Source

    -type wxMouse() ::
              #wxMouse{type :: wxMouseEvent:wxMouseEventType(),
                       x :: integer(),
                       y :: integer(),
                       leftDown :: boolean(),
                       middleDown :: boolean(),
                       rightDown :: boolean(),
                       controlDown :: boolean(),
                       shiftDown :: boolean(),
                       altDown :: boolean(),
                       metaDown :: boolean(),
                       wheelRotation :: integer(),
                       wheelDelta :: integer(),
                       linesPerAction :: integer()}.

Link to this type

# wxMouseEvent()

View Source

    -type wxMouseEvent() :: wx:wx_object().

Link to this type

# wxMouseEventType()

View Source

    -type wxMouseEventType() ::
              left_down | left_up | middle_down | middle_up | right_down | right_up | motion |
              enter_window | leave_window | left_dclick | middle_dclick | right_dclick | mousewheel |
              aux1_down | aux1_up | aux1_dclick | aux2_down | aux2_up | aux2_dclick.

# Functions

Link to this function

# altDown(This)

View Source

    -spec altDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the Alt key is pressed.

Notice that `wxKeyEvent:getModifiers/1` should usually be used instead of this one.

Link to this function

# aux1DClick(This)

View Source

    -spec aux1DClick(This) -> boolean() when This :: wxMouseEvent().

Returns true if the event was a first extra button double click.

Link to this function

# aux1Down(This)

View Source

    -spec aux1Down(This) -> boolean() when This :: wxMouseEvent().

Returns true if the first extra button mouse button changed to down.

Link to this function

# aux1Up(This)

View Source

    -spec aux1Up(This) -> boolean() when This :: wxMouseEvent().

Returns true if the first extra button mouse button changed to up.

Link to this function

# aux2DClick(This)

View Source

    -spec aux2DClick(This) -> boolean() when This :: wxMouseEvent().

Returns true if the event was a second extra button double click.

Link to this function

# aux2Down(This)

View Source

    -spec aux2Down(This) -> boolean() when This :: wxMouseEvent().

Returns true if the second extra button mouse button changed to down.

Link to this function

# aux2Up(This)

View Source

    -spec aux2Up(This) -> boolean() when This :: wxMouseEvent().

Returns true if the second extra button mouse button changed to up.

Link to this function

# button(This, But)

View Source

    -spec button(This, But) -> boolean() when This :: wxMouseEvent(), But :: wx:wx_enum().

Returns true if the event was generated by the specified button.

Link to this function

# buttonDClick(This)

View Source

    -spec buttonDClick(This) -> boolean() when This :: wxMouseEvent().

Equivalent to `buttonDClick(This, [])`.

Link to this function

# buttonDClick/2

View Source

    -spec buttonDClick(This, [Option]) -> boolean()
                          when This :: wxMouseEvent(), Option :: {but, wx:wx_enum()}.

If the argument is omitted, this returns true if the event was a mouse double click event.

Otherwise the argument specifies which double click event was generated (see `button/2` for the possible values).

Link to this function

# buttonDown(This)

View Source

    -spec buttonDown(This) -> boolean() when This :: wxMouseEvent().

Equivalent to `buttonDown(This, [])`.

Link to this function

# buttonDown/2

View Source

    -spec buttonDown(This, [Option]) -> boolean() when This :: wxMouseEvent(), Option :: {but, wx:wx_enum()}.

If the argument is omitted, this returns true if the event was a mouse button down event.

Otherwise the argument specifies which button-down event was generated (see `button/2` for the possible values).

Link to this function

# buttonUp(This)

View Source

    -spec buttonUp(This) -> boolean() when This :: wxMouseEvent().

Equivalent to `buttonUp(This, [])`.

Link to this function

# buttonUp/2

View Source

    -spec buttonUp(This, [Option]) -> boolean() when This :: wxMouseEvent(), Option :: {but, wx:wx_enum()}.

If the argument is omitted, this returns true if the event was a mouse button up event.

Otherwise the argument specifies which button-up event was generated (see `button/2` for the possible values).

Link to this function

# cmdDown(This)

View Source

    -spec cmdDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the key used for command accelerators is pressed.

Same as `controlDown/1`. Deprecated.

Notice that `wxKeyEvent:getModifiers/1` should usually be used instead of this one.

Link to this function

# controlDown(This)

View Source

    -spec controlDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the Control key or Apple/Command key under macOS is pressed.

This function doesn't distinguish between right and left control keys.

Notice that `wxKeyEvent:getModifiers/1` should usually be used instead of this one.

Link to this function

# dragging(This)

View Source

    -spec dragging(This) -> boolean() when This :: wxMouseEvent().

Returns true if this was a dragging event (motion while a button is depressed).

See: `moving/1`

Link to this function

# entering(This)

View Source

    -spec entering(This) -> boolean() when This :: wxMouseEvent().

Returns true if the mouse was entering the window.

See: `leaving/1`

Link to this function

# getButton(This)

View Source

    -spec getButton(This) -> integer() when This :: wxMouseEvent().

Returns the mouse button which generated this event or `wxMOUSE\_BTN\_NONE` if no button is involved (for mouse move, enter or leave event, for example).

Otherwise `wxMOUSE_BTN_LEFT` is returned for the left button down, up and double click events, `wxMOUSE_BTN_MIDDLE` and `wxMOUSE_BTN_RIGHT` for the same events for the middle and the right buttons respectively.

Link to this function

# getLinesPerAction(This)

View Source

    -spec getLinesPerAction(This) -> integer() when This :: wxMouseEvent().

Returns the configured number of lines (or whatever) to be scrolled per wheel action.

Default value under most platforms is three.

Link to this function

# getLogicalPosition(This, Dc)

View Source

    -spec getLogicalPosition(This, Dc) -> {X :: integer(), Y :: integer()}
                                when This :: wxMouseEvent(), Dc :: wxDC:wxDC().

Returns the logical mouse position in pixels (i.e. translated according to the translation set for the DC, which usually indicates that the window has been scrolled).

Link to this function

# getPosition(This)

View Source

    -spec getPosition(This) -> {X :: integer(), Y :: integer()} when This :: wxMouseEvent().

Returns the physical mouse position.

Link to this function

# getWheelAxis(This)

View Source

    -spec getWheelAxis(This) -> wx:wx_enum() when This :: wxMouseEvent().

Gets the axis the wheel operation concerns.

Usually the mouse wheel is used to scroll vertically so `wxMOUSE_WHEEL_VERTICAL` is returned but some mice (and most trackpads) also allow to use the wheel to scroll horizontally in which case `wxMOUSE_WHEEL_HORIZONTAL` is returned.

Notice that before wxWidgets 2.9.4 this method returned `int`.

Link to this function

# getWheelDelta(This)

View Source

    -spec getWheelDelta(This) -> integer() when This :: wxMouseEvent().

Get wheel delta, normally 120.

This is the threshold for action to be taken, and one such action (for example, scrolling one increment) should occur for each delta.

Link to this function

# getWheelRotation(This)

View Source

    -spec getWheelRotation(This) -> integer() when This :: wxMouseEvent().

Get wheel rotation, positive or negative indicates direction of rotation.

Current devices all send an event when rotation is at least +/-WheelDelta, but finer resolution devices can be created in the future.

Because of this you shouldn't assume that one event is equal to 1 line, but you should be able to either do partial line scrolling or wait until several events accumulate before scrolling.

Link to this function

# getX(This)

View Source

    -spec getX(This) -> integer() when This :: wxMouseEvent().

Returns X coordinate of the physical mouse event position.

Link to this function

# getY(This)

View Source

    -spec getY(This) -> integer() when This :: wxMouseEvent().

Returns Y coordinate of the physical mouse event position.

Link to this function

# isButton(This)

View Source

    -spec isButton(This) -> boolean() when This :: wxMouseEvent().

Returns true if the event was a mouse button event (not necessarily a button down event - that may be tested using `buttonDown/2`).

Link to this function

# isPageScroll(This)

View Source

    -spec isPageScroll(This) -> boolean() when This :: wxMouseEvent().

Returns true if the system has been setup to do page scrolling with the mouse wheel instead of line scrolling.

Link to this function

# leaving(This)

View Source

    -spec leaving(This) -> boolean() when This :: wxMouseEvent().

Returns true if the mouse was leaving the window.

See: `entering/1`

Link to this function

# leftDClick(This)

View Source

    -spec leftDClick(This) -> boolean() when This :: wxMouseEvent().

Returns true if the event was a left double click.

Link to this function

# leftDown(This)

View Source

    -spec leftDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the left mouse button changed to down.

Link to this function

# leftIsDown(This)

View Source

    -spec leftIsDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the left mouse button is currently down.

Link to this function

# leftUp(This)

View Source

    -spec leftUp(This) -> boolean() when This :: wxMouseEvent().

Returns true if the left mouse button changed to up.

Link to this function

# metaDown(This)

View Source

    -spec metaDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the Meta key was down at the time of the event.

Link to this function

# middleDClick(This)

View Source

    -spec middleDClick(This) -> boolean() when This :: wxMouseEvent().

Returns true if the event was a middle double click.

Link to this function

# middleDown(This)

View Source

    -spec middleDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the middle mouse button changed to down.

Link to this function

# middleIsDown(This)

View Source

    -spec middleIsDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the middle mouse button is currently down.

Link to this function

# middleUp(This)

View Source

    -spec middleUp(This) -> boolean() when This :: wxMouseEvent().

Returns true if the middle mouse button changed to up.

Link to this function

# moving(This)

View Source

    -spec moving(This) -> boolean() when This :: wxMouseEvent().

Returns true if this was a motion event and no mouse buttons were pressed.

If any mouse button is held pressed, then this method returns false and `dragging/1` returns true.

Link to this function

# rightDClick(This)

View Source

    -spec rightDClick(This) -> boolean() when This :: wxMouseEvent().

Returns true if the event was a right double click.

Link to this function

# rightDown(This)

View Source

    -spec rightDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the right mouse button changed to down.

Link to this function

# rightIsDown(This)

View Source

    -spec rightIsDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the right mouse button is currently down.

Link to this function

# rightUp(This)

View Source

    -spec rightUp(This) -> boolean() when This :: wxMouseEvent().

Returns true if the right mouse button changed to up.

Link to this function

# shiftDown(This)

View Source

    -spec shiftDown(This) -> boolean() when This :: wxMouseEvent().

Returns true if the Shift key is pressed.

This function doesn't distinguish between right and left shift keys.

Notice that `wxKeyEvent:getModifiers/1` should usually be used instead of this one.