wx.MouseEvent

Inheritance diagram for wx.MouseEvent:



Description

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 wx.MOUSE_BTN_LEFT for the left mouse button, wx.MOUSE_BTN_MIDDLE for the middle one and wx.MOUSE_BTN_RIGHT for the right one.

Note

Note that not all mice have a middle button so a portable application should avoid relying on the events from it.

Note

Note the difference between methods like LeftDown and LeftIsDown: 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 to test whether the left mouse button is (still) depressed. Also, by convention, if LeftDown returns True, LeftIsDown 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.

Derived From

Event Handling

Event Name Description
wx.EVT_LEFT_DOWN(func) Process a wx.wxEVT_LEFT_DOWN event. The handler of this event should normally call event.Skip() to allow the default processing to take place as otherwise the window under mouse wouldn’t get the focus.
wx.EVT_LEFT_UP(func) Process a wx.wxEVT_LEFT_UP event.
wx.EVT_LEFT_DCLICK(func) Process a wx.wxEVT_LEFT_DCLICK event.
wx.EVT_MIDDLE_DOWN(func) Process a wx.wxEVT_MIDDLE_DOWN event.
wx.EVT_MIDDLE_UP(func) Process a wx.wxEVT_MIDDLE_UP event.
wx.EVT_MIDDLE_DCLICK(func) Process a wx.wxEVT_MIDDLE_DCLICK event.
wx.EVT_RIGHT_DOWN(func) Process a wx.wxEVT_RIGHT_DOWN event.
wx.EVT_RIGHT_UP(func) Process a wx.wxEVT_RIGHT_UP event.
wx.EVT_RIGHT_DCLICK(func) Process a wx.wxEVT_RIGHT_DCLICK event.
wx.EVT_MOTION(func) Process a wx.wxEVT_MOTION event.
wx.EVT_ENTER_WINDOW(func) Process a wx.wxEVT_ENTER_WINDOW event.
wx.EVT_LEAVE_WINDOW(func) Process a wx.wxEVT_LEAVE_WINDOW event.
wx.EVT_MOUSEWHEEL(func) Process a wx.wxEVT_MOUSEWHEEL event.
wx.EVT_MOUSE_EVENTS(func) Process all mouse events.

Class API

Methods

__init__(mouseType=wx.wxEVT_NULL)

Constructs a wx.MouseEvent. Valid event types are:

  • wx.EVT_ENTER_WINDOW
  • wx.EVT_LEAVE_WINDOW
  • wx.EVT_LEFT_DOWN
  • wx.EVT_LEFT_UP
  • wx.EVT_LEFT_DCLICK
  • wx.EVT_MIDDLE_DOWN
  • wx.EVT_MIDDLE_UP
  • wx.EVT_MIDDLE_DCLICK
  • wx.EVT_RIGHT_DOWN
  • wx.EVT_RIGHT_UP
  • wx.EVT_RIGHT_DCLICK
  • wx.EVT_MOTION
  • wx.EVT_MOUSEWHEEL

Parameters:

  • mouseType (eventtype)

Returns:

wx.MouseEvent


AltDown()

Returns True if the Alt key was down at the time of the event.


Returns:

bool


ButtonDClick(but=wx.MOUSE_BTN_ANY)

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 GetButton for the possible values).

Parameters:

  • but (int)

Returns:

bool


ButtonDown(but=-1)

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 GetButton for the possible values).

Parameters:

  • but (int)

Returns:

bool


ButtonIsDown(but)

Parameters:

  • but (int)

Returns:

bool


ButtonUp(but=-1)

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

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

Parameters:

  • but (int)

Returns:

bool


CmdDown()

Same as MetaDown under Mac, same as ControlDown elsewhere.


Returns:

bool


ControlDown()

Returns True if the control key was down at the time of the event.


Returns:

bool


Dragging()

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


Returns:

bool

See also

Moving


Entering()

Returns True if the mouse was entering the window.


Returns:

bool

See also

Leaving.


GetButton()

Returns the mouse button which generated this event or wx.MOUSE_BTN_NONE if no button is involved (for mouse move, enter or leave event, for example).

Otherwise wx.MOUSE_BTN_LEFT is returned for the left button down, up and double click events, wx.MOUSE_BTN_MIDDLE and wx.MOUSE_BTN_RIGHT for the same events for the middle and the right buttons respectively.


Returns:

int


GetLinesPerAction()

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

Defaults to three.


Returns:

int


GetLogicalPosition(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).

Parameters:


Returns:

wx.Point


GetPosition()

Returns the physical mouse position in pixels.


Returns:

wx.Point

Note

Note that if the mouse event has been artificially generated from a special keyboard combination (e.g. under Windows when the “menu” key is pressed), the returned position is wx.DefaultPosition.


GetPositionTuple()

Returns the pixel position of the mouse in window coordinates when the event happened.


Returns:

(x,y)


GetWheelDelta()

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.


Returns:

int


GetWheelRotation()

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.


Returns:

int


GetX()

Returns X coordinate of the physical mouse event position.


Returns:

long


GetY()

Returns Y coordinate of the physical mouse event position.


Returns:

long


IsButton()

Returns True if the event was a mouse button event (not necessarily a button down event - that may be tested using ButtonDown).


Returns:

bool


IsPageScroll()

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


Returns:

bool


Leaving()

Returns True if the mouse was leaving the window.


Returns:

bool

See also

Entering.


LeftDClick()

Returns True if the event was a left double click.


Returns:

bool


LeftDown()

Returns True if the left mouse button changed to down.


Returns:

bool


LeftIsDown()

Returns True if the left mouse button is currently down, independent of the current event type.

Please notice that it is not the same as LeftDown which returns True if the event was generated by the left mouse button being pressed. Rather, it simply describes the state of the left mouse button at the time when the event was generated (so while it will be True for a left click event, it can also be True for a right click if it happened while the left mouse button was pressed).

This event is usually used in the mouse event handlers which process “move mouse” messages to determine whether the user is (still) dragging the mouse.


Returns:

bool


LeftUp()

Returns True if the left mouse button changed to up.


Returns:

bool


MetaDown()

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


Returns:

bool


MiddleDClick()

Returns True if the event was a middle double click.


Returns:

bool


MiddleDown()

Returns True if the middle mouse button changed to down.


Returns:

bool


MiddleIsDown()

Returns True if the middle mouse button is currently down, independent of the current event type.


Returns:

bool


MiddleUp()

Returns True if the middle mouse button changed to up.


Returns:

bool


Moving()

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 returns True.


Returns:

bool


RightDClick()

Returns True if the event was a right double click.


Returns:

bool


RightDown()

Returns True if the right mouse button changed to down.


Returns:

bool


RightIsDown()

Returns True if the right mouse button is currently down, independent of the current event type.


Returns:

bool


RightUp()

Returns True if the right mouse button changed to up.


Returns:

bool


ShiftDown()

Returns True if the shift key was down at the time of the event.


Returns:

bool


Properties

Button
See GetButton
LinesPerAction
See GetLinesPerAction
LogicalPosition
See GetLogicalPosition
Position
See GetPosition
WheelDelta
See GetWheelDelta
WheelRotation
See GetWheelRotation
X
See GetX
Y
See GetY
m_altDown
See AltDown
m_controlDown
See ControlDown
m_leftDown
See LeftDown
m_linesPerAction
See GetLinesPerAction
m_metaDown
See MetaDown
m_middleDown
See MiddleDown
m_rightDown
See RightDown
m_shiftDown
See ShiftDown
m_wheelDelta
See GetWheelDelta
m_wheelRotation
See GetWheelRotation
m_x
See GetX
m_y
See GetY