Permalink
Browse files

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
  • Loading branch information...
kollivier committed Mar 6, 2010
1 parent 917f228 commit a02a5cfcf33bb2c0edae246c1b19e286bf86d422
@@ -727,6 +727,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/common/textentrycmn.cpp
src/common/toplvcmn.cpp
src/common/treebase.cpp
src/common/uiactioncmn.cpp
src/common/valgen.cpp
src/common/validate.cpp
src/common/valtext.cpp
@@ -966,6 +967,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
wx/treebase.h
wx/treebook.h
wx/treectrl.h
wx/uiaction.h
wx/valgen.h
wx/vidmode.h
wx/vlbox.h
@@ -991,10 +993,11 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/generic/caret.cpp
src/generic/imaglist.cpp
src/unix/dialup.cpp
src/unix/displayx11.cpp
src/unix/fontenum.cpp
src/unix/fontutil.cpp
src/unix/uiactionx11.cpp
src/unix/utilsx11.cpp
src/unix/displayx11.cpp
</set>
<set var="XWIN_LOWLEVEL_HDR" hints="files">
wx/generic/caret.h
@@ -1710,6 +1713,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/msw/textentry.cpp
src/msw/tglbtn.cpp
src/msw/treectrl.cpp
src/msw/uiaction.cpp
</set>
<set var="MSW_HDR" hints="files">
wx/generic/clrpickerg.h
@@ -2257,6 +2261,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/osx/textctrl_osx.cpp
src/osx/tglbtn_osx.cpp
src/osx/toolbar_osx.cpp
src/osx/uiaction_osx.cpp
<!-- wxWebKit files -->
src/html/htmlctrl/webkit/webkit.mm
<!-- Native color/font dialogs -->
View
@@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////
// Name: include/wx/uiaction.cpp
// Purpose: wxUIActionSimulator interface
// Author: Kevin Ollivier
// Modified by:
// Created: 2010-03-06
// RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
// Copyright: (c) Kevin Ollivier
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _UIACTIONSIMULATOR_H_
#define _UIACTIONSIMULATOR_H_
#include <wx/defs.h>
#include <wx/event.h>
#include <wx/dynarray.h>
class WXDLLIMPEXP_CORE wxUIActionSimulator
{
public:
wxUIActionSimulator();
~wxUIActionSimulator();
// Mouse related
bool MouseMove(long x, long y);
bool MouseDown(int button = wxMOUSE_BTN_LEFT);
bool MouseUp(int button = wxMOUSE_BTN_LEFT);
bool MouseClick(int button = wxMOUSE_BTN_LEFT);
bool MouseDblClick(int button = wxMOUSE_BTN_LEFT);
bool MouseDragDrop(long x1, long y1, long x2, long y2, int button = wxMOUSE_BTN_LEFT);
// Keyboard related:
bool KeyDown(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false)
{ return Key(keycode, true, shiftDown, cmdDown, altDown); }
bool KeyUp(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false)
{ return Key(keycode, false, shiftDown, cmdDown, altDown); }
bool Char(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
protected:
// Implementation-wise, since key events take more code to set up on GTK and Mac, it makes
// sense to handle both key down and key up in one method. However, I wanted the API for pressing
// and releasing the mouse and keyboard to be consistent, and I don't really like using a bool
// for pressed state, so I'm leaving this as an implementation detail.
bool Key(int keycode, bool isDown=true, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
};
#endif
View
@@ -0,0 +1,150 @@
/////////////////////////////////////////////////////////////////////////////
// Name: uiaction.h
// Purpose: interface of wxUIActionSimulator
// Author: wxWidgets team
// RCS-ID: $Id$
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
/**
@class wxUIActionSimulator
wxUIActionSimulator is a class used to simulate user interface actions
such as a mouse click or a key press.
Common usages 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 uiaction sample for example usage of this class.
NOTE: For keyboard operations, currently you must pass the keycode of the actual
key on the keyboard. To simulate, e.g. IME actions, you'd need to simulate the actual
keypresses needed to active the IME, then the keypresses needed to type and select
the desired character.
@library{wxcore}
*/
class wxUIActionSimulator
{
public:
/**
Constructor.
*/
wxUIActionSimulator();
~wxUIActionSimulator();
/**
Move the mouse to the specified coordinates.
@param x
x coordinate to move to, in screen coordinates.
@param y
y coordinate to move to, in screen coordinates.
*/
bool MouseMove(long x, long y);
/**
Press a mouse button.
@param button
Button to press. Valid constants are wxMOUSE_BTN_LEFT, wxMOUSE_BTN_MIDDLE, and wxMOUSE_BTN_RIGHT.
*/
bool MouseDown(int button = wxMOUSE_BTN_LEFT);
/**
Release a mouse button.
@param button
Button to press. See wxUIActionSimulator::MouseDown for a list of valid constants.
*/
bool MouseUp(int button = wxMOUSE_BTN_LEFT);
/**
Click a mouse button.
@param button
Button to press. See wxUIActionSimulator::MouseDown for a list of valid constants.
*/
bool MouseClick(int button = wxMOUSE_BTN_LEFT);
/**
Double-click a mouse button.
@param button
Button to press. See wxUIActionSimulator::MouseDown for a list of valid constants.
*/
bool MouseDblClick(int button = wxMOUSE_BTN_LEFT);
/**
Perform a drag and drop operation.
@param x1
x start coordinate, in screen coordinates.
@param y1
y start coordinate, in screen coordinates.
@param x2
x desintation coordinate, in screen coordinates.
@param y2
y destination coordinate, in screen coordinates.
@param button
Button to press. See wxUIActionSimulator::MouseDown for a list of valid constants.
*/
bool MouseDragDrop(long x1, long y1, long x2, long y2, int button = wxMOUSE_BTN_LEFT);
/**
Press a key.
@param keycode
key to operate on, as an integer.
@param shiftDown
true if the shift key should be pressed, false otherwise.
@param cmdDown
true if the cmd key should be pressed, false otherwise.
@param altDown
true if the alt key should be pressed, false otherwise.
*/
bool KeyDown(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
/**
Release a key.
@param keycode
key to operate on, as an integer.
@param shiftDown
true if the shift key should be pressed, false otherwise.
@param cmdDown
true if the cmd key should be pressed, false otherwise.
@param altDown
true if the alt key should be pressed, false otherwise.
*/
bool KeyUp(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
/**
Press and release a key.
@param keycode
key to operate on, as an integer.
@param shiftDown
true if the shift key should be pressed, false otherwise.
@param cmdDown
true if the cmd key should be pressed, false otherwise.
@param altDown
true if the alt key should be pressed, false otherwise.
*/
bool Char(int keycode, bool shiftDown=false, bool cmdDown=false, bool altDown=false);
};
#endif
View
@@ -84,6 +84,7 @@
<subproject id="toolbar" template="sub"/>
<subproject id="treectrl" template="sub"/>
<subproject id="typetest" template="sub"/>
<subproject id="uiaction" template="sub"/>
<subproject id="validate" template="sub"/>
<subproject id="vscroll" template="sub"/>
<subproject id="widgets" template="sub"/>
@@ -0,0 +1,15 @@
<?xml version="1.0" ?>
<!-- $Id$ -->
<makefile>
<include file="../../build/bakefiles/common_samples.bkl"/>
<exe id="uiaction" template="wx_sample" template_append="wx_append">
<sources>uiaction.cpp</sources>
<wx-lib>core</wx-lib>
<wx-lib>base</wx-lib>
<uid type="creatorid">wx06</uid>
</exe>
</makefile>
Oops, something went wrong.

0 comments on commit a02a5cf

Please sign in to comment.