-
Notifications
You must be signed in to change notification settings - Fork 5
/
SendKeys.h
executable file
·86 lines (70 loc) · 2.18 KB
/
SendKeys.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef __SENDKEYS_04192004__INC__
#define __SENDKEYS_04192004__INC__
#include <windows.h>
#include <tchar.h>
/**
* SendKeys.h
*
* This is a modified version of SendKeys in C++ by [email protected].
*
* http://www.codeproject.com/cpp/sendkeys_cpp_Article.asp
*/
// Please see SendKeys.cpp for copyright and usage issues.
class CSendKeys
{
private:
bool m_bWait, m_bUsingParens, m_bShiftDown, m_bAltDown, m_bControlDown, m_bWinDown;
DWORD m_nDelayAlways, m_nDelayNow;
static BOOL CALLBACK enumwindowsProc(HWND hwnd, LPARAM lParam);
void CarryDelay();
typedef BYTE KEYBOARDSTATE_t[256];
struct enumwindow_t
{
LPTSTR str;
HWND hwnd;
};
struct key_desc_t
{
LPCTSTR keyName;
BYTE VKey;
bool normalkey; // a normal character or a VKEY ?
};
enum
{
MaxSendKeysRecs = 71,
MaxExtendedVKeys = 11
};
/*
Reference: VkKeyScan() / MSDN
Bit Meaning
--- --------
1 Either SHIFT key is pressed.
2 Either CTRL key is pressed.
4 Either ALT key is pressed.
8 The Hankaku key is pressed
16 Reserved (defined by the keyboard layout driver).
32 Reserved (defined by the keyboard layout driver).
*/
static const WORD VKKEYSCANSHIFTON;
static const WORD VKKEYSCANCTRLON;
static const WORD VKKEYSCANALTON;
static const WORD VKKEYSCANRALTON;
static const WORD INVALIDKEY;
static key_desc_t KeyNames[MaxSendKeysRecs];
static const BYTE ExtendedVKeys[MaxExtendedVKeys];
static bool BitSet(BYTE BitTable, UINT BitMask);
void PopUpShiftKeys();
static bool IsVkExtended(BYTE VKey);
void SendKeyUp(BYTE VKey);
void SendKeyDown(BYTE VKey, WORD NumTimes, bool GenUpMsg, bool bDelay = false);
void SendKey(WORD MKey, WORD NumTimes, bool GenDownMsg);
static WORD StringToVKey(LPCTSTR KeyString, int &idx);
void KeyboardEvent(BYTE VKey, BYTE ScanCode, LONG Flags);
public:
bool SendKeys(LPCTSTR KeysString, bool Wait = false);
static bool AppActivate(HWND wnd);
static bool AppActivate(LPCTSTR WindowTitle, LPCTSTR WindowClass = 0);
void SetDelay(const DWORD delay) { m_nDelayAlways = delay; }
CSendKeys();
};
#endif