forked from wxWidgets/wxWidgets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
10 changed files
with
776 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.