.. include:: headings.inc .. _MouseEvent: ========================================================================================================================================== |phoenix_title| **MouseEvent** ========================================================================================================================================== 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 ``MOUSE_BTN_LEFT`` for the left mouse button, ``MOUSE_BTN_MIDDLE`` for the middle one and ``MOUSE_BTN_RIGHT`` for the right one. And if the system supports more buttons, the ``MOUSE_BTN_AUX1`` and ``MOUSE_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 :meth:`Window.ClientToScreen` to convert it to screen coordinates and possibly call :meth:`Window.ScreenToClient` next to convert it to window coordinates of another window. .. _MouseEvent-events: |events| Events Emitted by this Class ===================================== Handlers bound for the following event types will receive a :ref:`MouseEvent` parameter. - EVT_LEFT_DOWN: Process a ``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. - EVT_LEFT_UP: Process a ``wxEVT_LEFT_UP`` event. - EVT_LEFT_DCLICK: Process a ``wxEVT_LEFT_DCLICK`` event. - EVT_MIDDLE_DOWN: Process a ``wxEVT_MIDDLE_DOWN`` event. - EVT_MIDDLE_UP: Process a ``wxEVT_MIDDLE_UP`` event. - EVT_MIDDLE_DCLICK: Process a ``wxEVT_MIDDLE_DCLICK`` event. - EVT_RIGHT_DOWN: Process a ``wxEVT_RIGHT_DOWN`` event. - EVT_RIGHT_UP: Process a ``wxEVT_RIGHT_UP`` event. - EVT_RIGHT_DCLICK: Process a ``wxEVT_RIGHT_DCLICK`` event. - EVT_MOUSE_AUX1_DOWN: Process a ``wxEVT_AUX1_DOWN`` event. - EVT_MOUSE_AUX1_UP: Process a ``wxEVT_AUX1_UP`` event. - EVT_MOUSE_AUX1_DCLICK: Process a ``wxEVT_AUX1_DCLICK`` event. - EVT_MOUSE_AUX2_DOWN: Process a ``wxEVT_AUX2_DOWN`` event. - EVT_MOUSE_AUX2_UP: Process a ``wxEVT_AUX2_UP`` event. - EVT_MOUSE_AUX2_DCLICK: Process a ``wxEVT_AUX2_DCLICK`` event. - EVT_MOTION: Process a ``wxEVT_MOTION`` event. - EVT_ENTER_WINDOW: Process a ``wxEVT_ENTER_WINDOW`` event. - EVT_LEAVE_WINDOW: Process a ``wxEVT_LEAVE_WINDOW`` event. - EVT_MOUSEWHEEL: Process a ``wxEVT_MOUSEWHEEL`` event. - EVT_MOUSE_EVENTS: Process all mouse events. .. note:: Note that under Windows ``CE`` mouse enter and leave events are not natively supported by the system but are generated by wxWidgets itself. This has several drawbacks: the ``LEAVE_WINDOW`` event might be received some time after the mouse left the window and the state variables for it may have changed during this time. Note the difference between methods like :meth:`MouseEvent.LeftDown` and the inherited :meth:`MouseState.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 :meth:`MouseEvent.LeftIsDown` to test whether the left mouse button is (still) depressed. Also, by convention, if :meth:`MouseEvent.LeftDown` returns ``True``, :meth:`MouseEvent.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. .. seealso:: :ref:`KeyEvent` | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **MouseEvent** .. raw:: html

Inheritance diagram of MouseEvent

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~MouseEvent.__init__` Constructor. :meth:`~MouseEvent.Aux1DClick` Returns ``True`` if the event was a first extra button float click. :meth:`~MouseEvent.Aux1Down` Returns ``True`` if the first extra button mouse button changed to down. :meth:`~MouseEvent.Aux1Up` Returns ``True`` if the first extra button mouse button changed to up. :meth:`~MouseEvent.Aux2DClick` Returns ``True`` if the event was a second extra button float click. :meth:`~MouseEvent.Aux2Down` Returns ``True`` if the second extra button mouse button changed to down. :meth:`~MouseEvent.Aux2Up` Returns ``True`` if the second extra button mouse button changed to up. :meth:`~MouseEvent.Button` Returns ``True`` if the event was generated by the specified button. :meth:`~MouseEvent.ButtonDClick` If the argument is omitted, this returns ``True`` if the event was a mouse float click event. :meth:`~MouseEvent.ButtonDown` If the argument is omitted, this returns ``True`` if the event was a mouse button down event. :meth:`~MouseEvent.ButtonUp` If the argument is omitted, this returns ``True`` if the event was a mouse button up event. :meth:`~MouseEvent.Dragging` Returns ``True`` if this was a dragging event (motion while a button is depressed). :meth:`~MouseEvent.Entering` Returns ``True`` if the mouse was entering the window. :meth:`~MouseEvent.GetButton` Returns the mouse button which generated this event or ``MOUSE_BTN_NONE`` if no button is involved (for mouse move, enter or leave event, for example). :meth:`~MouseEvent.GetClickCount` Returns the number of mouse clicks for this event: 1 for a simple click, 2 for a double-click, 3 for a triple-click and so on. :meth:`~MouseEvent.GetLinesPerAction` Returns the configured number of lines (or whatever) to be scrolled per wheel action. :meth:`~MouseEvent.GetLogicalPosition` Returns the logical mouse position in pixels (i.e. :meth:`~MouseEvent.GetWheelAxis` Gets the axis the wheel operation concerns. :meth:`~MouseEvent.GetWheelDelta` Get wheel delta, normally 120. :meth:`~MouseEvent.GetWheelRotation` Get wheel rotation, positive or negative indicates direction of rotation. :meth:`~MouseEvent.IsButton` Returns ``True`` if the event was a mouse button event (not necessarily a button down event - that may be tested using :meth:`ButtonDown` ). :meth:`~MouseEvent.IsPageScroll` Returns ``True`` if the system has been setup to do page scrolling with the mouse wheel instead of line scrolling. :meth:`~MouseEvent.Leaving` Returns ``True`` if the mouse was leaving the window. :meth:`~MouseEvent.LeftDClick` Returns ``True`` if the event was a left float click. :meth:`~MouseEvent.LeftDown` Returns ``True`` if the left mouse button changed to down. :meth:`~MouseEvent.LeftUp` Returns ``True`` if the left mouse button changed to up. :meth:`~MouseEvent.MetaDown` Returns ``True`` if the Meta key was down at the time of the event. :meth:`~MouseEvent.MiddleDClick` Returns ``True`` if the event was a middle float click. :meth:`~MouseEvent.MiddleDown` Returns ``True`` if the middle mouse button changed to down. :meth:`~MouseEvent.MiddleUp` Returns ``True`` if the middle mouse button changed to up. :meth:`~MouseEvent.Moving` Returns ``True`` if this was a motion event and no mouse buttons were pressed. :meth:`~MouseEvent.RightDClick` Returns ``True`` if the event was a right float click. :meth:`~MouseEvent.RightDown` Returns ``True`` if the right mouse button changed to down. :meth:`~MouseEvent.RightUp` Returns ``True`` if the right mouse button changed to up. ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~MouseEvent.LinesPerAction` See :meth:`~MouseEvent.GetLinesPerAction` :attr:`~MouseEvent.LogicalPosition` See :meth:`~MouseEvent.GetLogicalPosition` :attr:`~MouseEvent.WheelDelta` See :meth:`~MouseEvent.GetWheelDelta` :attr:`~MouseEvent.WheelRotation` See :meth:`~MouseEvent.GetWheelRotation` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: MouseEvent(Event, MouseState) This event class contains information about the events generated by the mouse: they include mouse buttons press and release events and mouse move events. **Possible constructors**:: MouseEvent(mouseEventType=wxEVT_NULL) .. method:: __init__(self, mouseEventType=wxEVT_NULL) Constructor. Valid event types are: - ``wxEVT_ENTER_WINDOW`` - ``wxEVT_LEAVE_WINDOW`` - ``wxEVT_LEFT_DOWN`` - ``wxEVT_LEFT_UP`` - ``wxEVT_LEFT_DCLICK`` - ``wxEVT_MIDDLE_DOWN`` - ``wxEVT_MIDDLE_UP`` - ``wxEVT_MIDDLE_DCLICK`` - ``wxEVT_RIGHT_DOWN`` - ``wxEVT_RIGHT_UP`` - ``wxEVT_RIGHT_DCLICK`` - ``wxEVT_AUX1_DOWN`` - ``wxEVT_AUX1_UP`` - ``wxEVT_AUX1_DCLICK`` - ``wxEVT_AUX2_DOWN`` - ``wxEVT_AUX2_UP`` - ``wxEVT_AUX2_DCLICK`` - ``wxEVT_MOTION`` - ``wxEVT_MOUSEWHEEL`` :param `mouseEventType`: :type `mouseEventType`: EventType .. method:: Aux1DClick(self) Returns ``True`` if the event was a first extra button float click. :rtype: `bool` .. method:: Aux1Down(self) Returns ``True`` if the first extra button mouse button changed to down. :rtype: `bool` .. method:: Aux1Up(self) Returns ``True`` if the first extra button mouse button changed to up. :rtype: `bool` .. method:: Aux2DClick(self) Returns ``True`` if the event was a second extra button float click. :rtype: `bool` .. method:: Aux2Down(self) Returns ``True`` if the second extra button mouse button changed to down. :rtype: `bool` .. method:: Aux2Up(self) Returns ``True`` if the second extra button mouse button changed to up. :rtype: `bool` .. method:: Button(self, but) Returns ``True`` if the event was generated by the specified button. :param `but`: :type `but`: MouseButton :rtype: `bool` .. seealso:: `MouseState.ButtoinIsDown()` .. method:: ButtonDClick(self, but=MOUSE_BTN_ANY) If the argument is omitted, this returns ``True`` if the event was a mouse float click event. Otherwise the argument specifies which float click event was generated (see :meth:`Button` for the possible values). :param `but`: :type `but`: MouseButton :rtype: `bool` .. method:: ButtonDown(self, but=MOUSE_BTN_ANY) 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 :meth:`Button` for the possible values). :param `but`: :type `but`: MouseButton :rtype: `bool` .. method:: ButtonUp(self, but=MOUSE_BTN_ANY) 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 :meth:`Button` for the possible values). :param `but`: :type `but`: MouseButton :rtype: `bool` .. method:: Dragging(self) Returns ``True`` if this was a dragging event (motion while a button is depressed). :rtype: `bool` .. seealso:: :meth:`Moving` .. method:: Entering(self) Returns ``True`` if the mouse was entering the window. :rtype: `bool` .. seealso:: :meth:`Leaving` .. method:: GetButton(self) Returns the mouse button which generated this event or ``MOUSE_BTN_NONE`` if no button is involved (for mouse move, enter or leave event, for example). Otherwise ``MOUSE_BTN_LEFT`` is returned for the left button down, up and float click events, ``MOUSE_BTN_MIDDLE`` and ``MOUSE_BTN_RIGHT`` for the same events for the middle and the right buttons respectively. :rtype: `int` .. method:: GetClickCount(self) Returns the number of mouse clicks for this event: 1 for a simple click, 2 for a double-click, 3 for a triple-click and so on. Currently this function is implemented only in Mac and returns -1 for the other platforms (you can still distinguish simple clicks from double-clicks as they generate different kinds of events however). :rtype: `int` .. versionadded:: 2.9.0 .. method:: GetLinesPerAction(self) Returns the configured number of lines (or whatever) to be scrolled per wheel action. Defaults to three. :rtype: `int` .. method:: GetLogicalPosition(self, 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). :param `dc`: :type `dc`: DC :rtype: :ref:`Point` .. method:: GetWheelAxis(self) Gets the axis the wheel operation concerns. Usually the mouse wheel is used to scroll vertically so ``MOUSE_WHEEL_VERTICAL`` is returned but some mice (and most trackpads) also allow to use the wheel to scroll horizontally in which case ``MOUSE_WHEEL_HORIZONTAL`` is returned. Notice that before wxWidgets 2.9.4 this method returned ``int`` . :rtype: :ref:`MouseWheelAxis` .. method:: GetWheelDelta(self) 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. :rtype: `int` .. method:: GetWheelRotation(self) 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. :rtype: `int` .. method:: IsButton(self) Returns ``True`` if the event was a mouse button event (not necessarily a button down event - that may be tested using :meth:`ButtonDown` ). :rtype: `bool` .. method:: IsPageScroll(self) Returns ``True`` if the system has been setup to do page scrolling with the mouse wheel instead of line scrolling. :rtype: `bool` .. method:: Leaving(self) Returns ``True`` if the mouse was leaving the window. :rtype: `bool` .. seealso:: :meth:`Entering` . .. method:: LeftDClick(self) Returns ``True`` if the event was a left float click. :rtype: `bool` .. method:: LeftDown(self) Returns ``True`` if the left mouse button changed to down. :rtype: `bool` .. method:: LeftUp(self) Returns ``True`` if the left mouse button changed to up. :rtype: `bool` .. method:: MetaDown(self) Returns ``True`` if the Meta key was down at the time of the event. :rtype: `bool` .. method:: MiddleDClick(self) Returns ``True`` if the event was a middle float click. :rtype: `bool` .. method:: MiddleDown(self) Returns ``True`` if the middle mouse button changed to down. :rtype: `bool` .. method:: MiddleUp(self) Returns ``True`` if the middle mouse button changed to up. :rtype: `bool` .. method:: Moving(self) 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 :meth:`Dragging` returns ``True``. :rtype: `bool` .. method:: RightDClick(self) Returns ``True`` if the event was a right float click. :rtype: `bool` .. method:: RightDown(self) Returns ``True`` if the right mouse button changed to down. :rtype: `bool` .. method:: RightUp(self) Returns ``True`` if the right mouse button changed to up. :rtype: `bool` .. attribute:: LinesPerAction See :meth:`~MouseEvent.GetLinesPerAction` .. attribute:: LogicalPosition See :meth:`~MouseEvent.GetLogicalPosition` .. attribute:: WheelDelta See :meth:`~MouseEvent.GetWheelDelta` .. attribute:: WheelRotation See :meth:`~MouseEvent.GetWheelRotation`