Skip to content

Commit a02a5cf

Browse files
committed
Adding wxUIActionSimulator, a class for programmatically controlling the mouse and keyboard.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63644 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
1 parent 917f228 commit a02a5cf

File tree

10 files changed

+776
-1
lines changed

10 files changed

+776
-1
lines changed

build/bakefiles/files.bkl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
727727
src/common/textentrycmn.cpp
728728
src/common/toplvcmn.cpp
729729
src/common/treebase.cpp
730+
src/common/uiactioncmn.cpp
730731
src/common/valgen.cpp
731732
src/common/validate.cpp
732733
src/common/valtext.cpp
@@ -966,6 +967,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
966967
wx/treebase.h
967968
wx/treebook.h
968969
wx/treectrl.h
970+
wx/uiaction.h
969971
wx/valgen.h
970972
wx/vidmode.h
971973
wx/vlbox.h
@@ -991,10 +993,11 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
991993
src/generic/caret.cpp
992994
src/generic/imaglist.cpp
993995
src/unix/dialup.cpp
996+
src/unix/displayx11.cpp
994997
src/unix/fontenum.cpp
995998
src/unix/fontutil.cpp
999+
src/unix/uiactionx11.cpp
9961000
src/unix/utilsx11.cpp
997-
src/unix/displayx11.cpp
9981001
</set>
9991002
<set var="XWIN_LOWLEVEL_HDR" hints="files">
10001003
wx/generic/caret.h
@@ -1710,6 +1713,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
17101713
src/msw/textentry.cpp
17111714
src/msw/tglbtn.cpp
17121715
src/msw/treectrl.cpp
1716+
src/msw/uiaction.cpp
17131717
</set>
17141718
<set var="MSW_HDR" hints="files">
17151719
wx/generic/clrpickerg.h
@@ -2257,6 +2261,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
22572261
src/osx/textctrl_osx.cpp
22582262
src/osx/tglbtn_osx.cpp
22592263
src/osx/toolbar_osx.cpp
2264+
src/osx/uiaction_osx.cpp
22602265
<!-- wxWebKit files -->
22612266
src/html/htmlctrl/webkit/webkit.mm
22622267
<!-- Native color/font dialogs -->

include/wx/uiaction.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/////////////////////////////////////////////////////////////////////////////
2+
// Name: include/wx/uiaction.cpp
3+
// Purpose: wxUIActionSimulator interface
4+
// Author: Kevin Ollivier
5+
// Modified by:
6+
// Created: 2010-03-06
7+
// RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
8+
// Copyright: (c) Kevin Ollivier
9+
// Licence: wxWindows licence
10+
/////////////////////////////////////////////////////////////////////////////
11+
12+
#ifndef _UIACTIONSIMULATOR_H_
13+
#define _UIACTIONSIMULATOR_H_
14+
15+
#include <wx/defs.h>
16+
#include <wx/event.h>
17+
#include <wx/dynarray.h>
18+
19+
class WXDLLIMPEXP_CORE wxUIActionSimulator
20+
{
21+
public:
22+
wxUIActionSimulator();
23+
~wxUIActionSimulator();
24+
25+
// Mouse related
26+
bool MouseMove(long x, long y);
27+
bool MouseDown(int button = wxMOUSE_BTN_LEFT);
28+
bool MouseUp(int button = wxMOUSE_BTN_LEFT);
29+
bool MouseClick(int button = wxMOUSE_BTN_LEFT);
30+
bool MouseDblClick(int button = wxMOUSE_BTN_LEFT);
31+
bool MouseDragDrop(long x1, long y1, long x2, long y2, int button = wxMOUSE_BTN_LEFT);
32+
33+
// Keyboard related:
34+
35+
bool KeyDown(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false)
36+
{ return Key(keycode, true, shiftDown, cmdDown, altDown); }
37+
38+
bool KeyUp(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false)
39+
{ return Key(keycode, false, shiftDown, cmdDown, altDown); }
40+
41+
bool Char(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
42+
43+
protected:
44+
// Implementation-wise, since key events take more code to set up on GTK and Mac, it makes
45+
// sense to handle both key down and key up in one method. However, I wanted the API for pressing
46+
// and releasing the mouse and keyboard to be consistent, and I don't really like using a bool
47+
// for pressed state, so I'm leaving this as an implementation detail.
48+
bool Key(int keycode, bool isDown=true, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
49+
};
50+
51+
#endif

interface/wx/uiaction.h

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/////////////////////////////////////////////////////////////////////////////
2+
// Name: uiaction.h
3+
// Purpose: interface of wxUIActionSimulator
4+
// Author: wxWidgets team
5+
// RCS-ID: $Id$
6+
// Licence: wxWindows license
7+
/////////////////////////////////////////////////////////////////////////////
8+
9+
/**
10+
@class wxUIActionSimulator
11+
12+
wxUIActionSimulator is a class used to simulate user interface actions
13+
such as a mouse click or a key press.
14+
15+
Common usages for this class would be to provide playback and record (aka macro recording)
16+
functionality for users, or to drive unit tests by simulating user sessions.
17+
18+
See the uiaction sample for example usage of this class.
19+
20+
NOTE: For keyboard operations, currently you must pass the keycode of the actual
21+
key on the keyboard. To simulate, e.g. IME actions, you'd need to simulate the actual
22+
keypresses needed to active the IME, then the keypresses needed to type and select
23+
the desired character.
24+
25+
@library{wxcore}
26+
*/
27+
28+
class wxUIActionSimulator
29+
{
30+
public:
31+
/**
32+
Constructor.
33+
*/
34+
wxUIActionSimulator();
35+
~wxUIActionSimulator();
36+
37+
/**
38+
Move the mouse to the specified coordinates.
39+
40+
@param x
41+
x coordinate to move to, in screen coordinates.
42+
43+
@param y
44+
y coordinate to move to, in screen coordinates.
45+
*/
46+
bool MouseMove(long x, long y);
47+
48+
/**
49+
Press a mouse button.
50+
51+
@param button
52+
Button to press. Valid constants are wxMOUSE_BTN_LEFT, wxMOUSE_BTN_MIDDLE, and wxMOUSE_BTN_RIGHT.
53+
*/
54+
bool MouseDown(int button = wxMOUSE_BTN_LEFT);
55+
56+
/**
57+
Release a mouse button.
58+
59+
@param button
60+
Button to press. See wxUIActionSimulator::MouseDown for a list of valid constants.
61+
*/
62+
bool MouseUp(int button = wxMOUSE_BTN_LEFT);
63+
/**
64+
Click a mouse button.
65+
66+
@param button
67+
Button to press. See wxUIActionSimulator::MouseDown for a list of valid constants.
68+
*/
69+
bool MouseClick(int button = wxMOUSE_BTN_LEFT);
70+
/**
71+
Double-click a mouse button.
72+
73+
@param button
74+
Button to press. See wxUIActionSimulator::MouseDown for a list of valid constants.
75+
*/
76+
bool MouseDblClick(int button = wxMOUSE_BTN_LEFT);
77+
78+
/**
79+
Perform a drag and drop operation.
80+
81+
@param x1
82+
x start coordinate, in screen coordinates.
83+
84+
@param y1
85+
y start coordinate, in screen coordinates.
86+
87+
@param x2
88+
x desintation coordinate, in screen coordinates.
89+
90+
@param y2
91+
y destination coordinate, in screen coordinates.
92+
93+
@param button
94+
Button to press. See wxUIActionSimulator::MouseDown for a list of valid constants.
95+
*/
96+
bool MouseDragDrop(long x1, long y1, long x2, long y2, int button = wxMOUSE_BTN_LEFT);
97+
98+
/**
99+
Press a key.
100+
101+
@param keycode
102+
key to operate on, as an integer.
103+
104+
@param shiftDown
105+
true if the shift key should be pressed, false otherwise.
106+
107+
@param cmdDown
108+
true if the cmd key should be pressed, false otherwise.
109+
110+
@param altDown
111+
true if the alt key should be pressed, false otherwise.
112+
*/
113+
bool KeyDown(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
114+
115+
/**
116+
Release a key.
117+
118+
@param keycode
119+
key to operate on, as an integer.
120+
121+
@param shiftDown
122+
true if the shift key should be pressed, false otherwise.
123+
124+
@param cmdDown
125+
true if the cmd key should be pressed, false otherwise.
126+
127+
@param altDown
128+
true if the alt key should be pressed, false otherwise.
129+
*/
130+
bool KeyUp(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
131+
132+
/**
133+
Press and release a key.
134+
135+
@param keycode
136+
key to operate on, as an integer.
137+
138+
@param shiftDown
139+
true if the shift key should be pressed, false otherwise.
140+
141+
@param cmdDown
142+
true if the cmd key should be pressed, false otherwise.
143+
144+
@param altDown
145+
true if the alt key should be pressed, false otherwise.
146+
*/
147+
bool Char(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
148+
};
149+
150+
#endif

samples/samples.bkl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<subproject id="toolbar" template="sub"/>
8585
<subproject id="treectrl" template="sub"/>
8686
<subproject id="typetest" template="sub"/>
87+
<subproject id="uiaction" template="sub"/>
8788
<subproject id="validate" template="sub"/>
8889
<subproject id="vscroll" template="sub"/>
8990
<subproject id="widgets" template="sub"/>

samples/uiaction/uiaction.bkl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" ?>
2+
<!-- $Id$ -->
3+
4+
<makefile>
5+
6+
<include file="../../build/bakefiles/common_samples.bkl"/>
7+
8+
<exe id="uiaction" template="wx_sample" template_append="wx_append">
9+
<sources>uiaction.cpp</sources>
10+
<wx-lib>core</wx-lib>
11+
<wx-lib>base</wx-lib>
12+
<uid type="creatorid">wx06</uid>
13+
</exe>
14+
15+
</makefile>

0 commit comments

Comments
 (0)