wx.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 UIActionSimulator Sample for an example of using this class.
New in version 2.9.2.
Note
This class currently doesn’t work when using Wayland with wxGTK.
Default constructor. |
|
Press and release a key. |
|
Press a key. |
|
Release a key. |
|
Click a mouse button. |
|
Double-click a mouse button. |
|
Press a mouse button. |
|
Perform a drag and drop operation. |
|
Move the mouse to the specified coordinates. |
|
Release a mouse button. |
|
Simulate selection of an item with the given text. |
|
Emulate typing in the keys representing the given string. |
wx.
UIActionSimulator
(object)¶Possible constructors:
UIActionSimulator()
UIActionSimulator is a class used to simulate user interface actions such as a mouse click or a key press.
__init__
(self)¶Default constructor.
Char
(self, keycode, modifiers=MOD_NONE)¶Press and release a key.
keycode (int) – Key to operate on, as an integer. It is interpreted as a KeyCode.
modifiers (int) – A combination of wx.KeyModifier flags to be pressed with the given keycode.
bool
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 macOS).
keycode (int) – Key to operate on, as an integer. It is interpreted as a KeyCode.
modifiers (int) – A combination of wx.KeyModifier flags to be pressed with the given keycode.
bool
KeyUp
(self, keycode, modifiers=MOD_NONE)¶Release a key.
keycode (int) – Key to operate on, as an integer. It is interpreted as a KeyCode.
modifiers (int) – A combination of wx.KeyModifier flags to be pressed with the given keycode.
bool
MouseClick
(self, button=MOUSE_BTN_LEFT)¶Click a mouse button.
button (int) – Button to press. See wx.UIActionSimulator.MouseDown
for a list of valid constants.
bool
MouseDblClick
(self, button=MOUSE_BTN_LEFT)¶Double-click a mouse button.
button (int) – Button to press. See wx.UIActionSimulator.MouseDown
for a list of valid constants.
bool
MouseDown
(self, button=MOUSE_BTN_LEFT)¶Press a mouse button.
button (int) – Button to press. Valid constants are MOUSE_BTN_LEFT
, MOUSE_BTN_MIDDLE
, and MOUSE_BTN_RIGHT
.
bool
MouseDragDrop
(self, x1, y1, x2, y2, button=MOUSE_BTN_LEFT)¶Perform a drag and drop operation.
x1 (long) – x start coordinate, in screen coordinates.
y1 (long) – y start coordinate, in screen coordinates.
x2 (long) – x destination coordinate, in screen coordinates.
y2 (long) – y destination coordinate, in screen coordinates.
button (int) – Button to press. See wx.UIActionSimulator.MouseDown
for a list of valid constants.
bool
MouseMove
(self, *args, **kw)¶MouseMove (self, x, y)
Move the mouse to the specified coordinates.
x (long) – x coordinate to move to, in screen coordinates.
y (long) – y coordinate to move to, in screen coordinates.
bool
MouseMove (self, point)
Move the mouse to the specified coordinates.
point (wx.Point) – Point to move to, in screen coordinates.
bool
MouseUp
(self, button=MOUSE_BTN_LEFT)¶Release a mouse button.
button (int) – Button to press. See wx.UIActionSimulator.MouseDown
for a list of valid constants.
bool
Select
(self, text)¶Simulate selection of an item with the given text.
This method selects an item in the currently focused wx.Choice, wx.ComboBox, wx.ListBox and similar controls. It does it by simulating keyboard events, so the behaviour should be the same as if the item was really selected by the user.
Notice that the implementation of this method uses wx.Yield
and so events can be dispatched from it.
text (string) – The text of the item to select.
bool
True
if the item text was successfully selected or False
if the currently focused window is not one of the controls allowing item selection or if the item with the given text was not found in it.
New in version 4.1/wxWidgets-3.1.0.
Text
(self, text)¶Emulate typing in the keys representing the given string.
Currently only the ASCII
letters are universally supported. Digits and punctuation characters can be used with the standard QWERTY
(US
) keyboard layout but may not work with other layouts.
text (int) – The string, containing only US
ASCII
characters, to type.
bool