CKeystrokeEngine was originally written to allow users of my product,
Macro Angel, to send keystrokes to the
active or to a selected window. Its functionality is similar to VB's
SendKeys's functionality, but it allows more complex operations. In addition
to sending keystrokes to the active window, by the help of
(which was also written for Macro Angel),
it can send keystrokes to only a specified window.
CKeystrokeEngine expression looks like this:
Hello CPians<ENTER><REPEAT 10>I love CP <END_REPEAT><ENTER>http:
All special keys are put between '<' and '>' characters. For example
to simulate an Enter key, you should use <ENTER>. Or to press Shift key,
use <SHIFT>. Here are some more examples:
- To send Ctrl+A use <CTRL>A
- To send Alt+F4 use <ALT><F4>
- To send Ctrl+Alt+Shift+A use <CTRL+ALT+SHIFT>A
- You can also use <CTRL+ALT>, <CTRL+SHIFT> and <ALT+SHIFT>
- To hold Shift key and many keys, use <SHIFT_LOCK>write your keys here<SHIFT_UNLOCK>
- You can also use <ALT_LOCK>, <ALT_UNLOCK>, <CTRL_LOCK> and <CTRL_UNLOCK>
- To add a delay use <DELAY xxx> where xxx is the amount of time in miliseconds. For example, <DELAY 1500> waits 1.5 seconds.
- To repeat a sequence of keys 100 times, use <REPEAT 100>you keys here<END_REPEAT>.
Please note that nested repeats are not supported
All other keys are listed in the sample application. Here are the public functions
CKeystrokeEngine (const CString &sKeys);
void SetPause (bool bPause, int nPause);
void SetSendToWnd (bool bSendToWnd);
void SetWndTitle (LPCSTR lpszTitle);
void SetWndClass (LPCSTR lpszClass);
void SetExactMatch (bool bExact);
void SetCaseSensitive (bool bCaseSensitive);
void SetReActivate (bool bReactivate, int nMiliseconds);
bool SendKeys ();
SetPause (bool bPause, int nPause)<br>
Adjusts how much time
should wait in-between
each key-press when sending keystrokes. On some faster machines,
may type the keys too quickly, flooding the keyboard buffer and causing unpredictable
results. Increasing this setting will prevent this from occurring.
SetSendToWnd (bool bSendToWnd)<br>
is true, then
keystrokes to a specified window. By this way, sending keystrokes to wrong windows
bSendToWnd is set to false, then active window gets all keystrokes.
SetWndTitle (LPCSTR lpszTitle)<br>
Sets the window title, to which the keystrokes will be sent. If
is set to NULL, then
does not searh for a window
title. Note that this is effective only if
SetWndClass (LPCSTR lpszClass)<br>
Sets the window class, to which the keystrokes will be sent. If
is set to NULL, then
does not search for a window
class. Note that this is effective only if
SetExactMatch (bool bExact)<br>
Specified whether the Windows title entered is a partial title match
or must match exactly. When set to false,
search for window titles that contain that text. Note that this is effective
SetCaseSensitive (bool bCaseSensitive)<br>
If enabled, Window Title/Window Class and Text searches would be
case sensitive. Note that this is effective only if
SetReActivate (bool bReActivate, int nMiliseconds)<br>
If bReActivate is set to true, then
automatically re-activates the window whenever it looses focus. If 0 seconds
is entered, then the window is immediately activated when it looses focus. Otherwise,
waits for the specified amount of time and then
re-activates the window.
Adding a delay before re-activating windows prevents collisions between applications
that are trying to send keystrokes at the same time.
Note that this is effective only if
SetSendToWnd (true)is used.
bReActivate is set to false, and specified window looses focus, then
SendKeys () function returns false.
bool SendKeys ()<br>
Finally, this functions sends the keys with the specifed options.
Use this function setting all attributes of
To get more information about the supported keywords, please use the sample
Some points that you should keep in mind
- To use
CKeystrokeEngine in your applications, copy
WindowEngine.h into your project and
KeystrokeEngine.h in your cpp file.
- This class uses its own syntax, instead of using VBs
SendKeys () syntax.
Please don't want me to change the syntax. My customers are really happy with
this syntax :)
- This class is not used in the current version of Macro
Angel. It will be used in the next version. Current version uses the same
syntax, but the implementation is not as good as this. But this is class is
not tested yet and may include some bugs. Please send me the bugs, so that
I can fix them. If you find a bug, please send me the String that causes is
not working properly. Also, please send me the real output and the expected
- If you have any suggestions, please let me know.