.. include:: headings.inc .. _UIActionSimulator: ========================================================================================================================================== |phoenix_title| **UIActionSimulator** ========================================================================================================================================== :ref:`UIActionSimulator` is a class used to simulate user interface actions such as a mouse click or a key press. Common usage for this class would be to provide playback and record (aka macro recording) functionality for users, or to drive unit tests by simulating user sessions. See the for an example of using this class. .. versionadded:: 2.9.2 | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **UIActionSimulator** .. raw:: html

Inheritance diagram of UIActionSimulator

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~UIActionSimulator.__init__` Default constructor. :meth:`~UIActionSimulator.Char` Press and release a key. :meth:`~UIActionSimulator.KeyDown` Press a key. :meth:`~UIActionSimulator.KeyUp` Release a key. :meth:`~UIActionSimulator.MouseClick` Click a mouse button. :meth:`~UIActionSimulator.MouseDblClick` Double-click a mouse button. :meth:`~UIActionSimulator.MouseDown` Press a mouse button. :meth:`~UIActionSimulator.MouseDragDrop` Perform a drag and drop operation. :meth:`~UIActionSimulator.MouseMove` Move the mouse to the specified coordinates. :meth:`~UIActionSimulator.MouseUp` Release a mouse button. :meth:`~UIActionSimulator.Text` Emulate typing in the keys representing the given string. ================================================================================ ================================================================================ | |api| Class API =============== .. class:: UIActionSimulator(object) UIActionSimulator is a class used to simulate user interface actions such as a mouse click or a key press. **Possible constructors**:: UIActionSimulator() .. method:: __init__(self) Default constructor. .. method:: Char(self, keycode, modifiers=MOD_NONE) Press and release a key. :param `keycode`: Key to operate on, as an integer. It is interpreted as a KeyCode. :type `keycode`: int :param `modifiers`: A combination of :ref:`KeyModifier` flags to be pressed with the given keycode. :type `modifiers`: int :rtype: `bool` .. method:: KeyDown(self, keycode, modifiers=MOD_NONE) Press a key. If you are using modifiers then it needs to be paired with an identical KeyUp or the modifiers will not be released (MSW and OSX). :param `keycode`: Key to operate on, as an integer. It is interpreted as a KeyCode. :type `keycode`: int :param `modifiers`: A combination of :ref:`KeyModifier` flags to be pressed with the given keycode. :type `modifiers`: int :rtype: `bool` .. method:: KeyUp(self, keycode, modifiers=MOD_NONE) Release a key. :param `keycode`: Key to operate on, as an integer. It is interpreted as a KeyCode. :type `keycode`: int :param `modifiers`: A combination of :ref:`KeyModifier` flags to be pressed with the given keycode. :type `modifiers`: int :rtype: `bool` .. method:: MouseClick(self, button=MOUSE_BTN_LEFT) Click a mouse button. :param `button`: Button to press. See :meth:`UIActionSimulator.MouseDown` for a list of valid constants. :type `button`: int :rtype: `bool` .. method:: MouseDblClick(self, button=MOUSE_BTN_LEFT) Double-click a mouse button. :param `button`: Button to press. See :meth:`UIActionSimulator.MouseDown` for a list of valid constants. :type `button`: int :rtype: `bool` .. method:: MouseDown(self, button=MOUSE_BTN_LEFT) Press a mouse button. :param `button`: Button to press. Valid constants are ``MOUSE_BTN_LEFT`` , ``MOUSE_BTN_MIDDLE`` , and ``MOUSE_BTN_RIGHT`` . :type `button`: int :rtype: `bool` .. method:: MouseDragDrop(self, x1, y1, x2, y2, button=MOUSE_BTN_LEFT) Perform a drag and drop operation. :param `x1`: x start coordinate, in screen coordinates. :type `x1`: long :param `y1`: y start coordinate, in screen coordinates. :type `y1`: long :param `x2`: x destination coordinate, in screen coordinates. :type `x2`: long :param `y2`: y destination coordinate, in screen coordinates. :type `y2`: long :param `button`: Button to press. See :meth:`UIActionSimulator.MouseDown` for a list of valid constants. :type `button`: int :rtype: `bool` .. method:: MouseMove(self, *args, **kw) |overload| **Overloaded Implementations**: **~~~** **MouseMove** `(self, x, y)` Move the mouse to the specified coordinates. :param `x`: x coordinate to move to, in screen coordinates. :type `x`: long :param `y`: y coordinate to move to, in screen coordinates. :type `y`: long :rtype: `bool` **~~~** **MouseMove** `(self, point)` Move the mouse to the specified coordinates. :param `point`: Point to move to, in screen coordinates. :type `point`: Point :rtype: `bool` **~~~** .. method:: MouseUp(self, button=MOUSE_BTN_LEFT) Release a mouse button. :param `button`: Button to press. See :meth:`UIActionSimulator.MouseDown` for a list of valid constants. :type `button`: int :rtype: `bool` .. method:: Text(self, text) Emulate typing in the keys representing the given string. Currently only the ``ASCII`` letters, digits and characters for the definition of numbers (i.e. characters ``a-z`` ``A-Z`` ``0-9`` ``+`` ``-`` ``'space'`` ) are supported. :param `text`: The string to type. :type `text`: string :rtype: `bool`