-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendKeys.h
100 lines (83 loc) · 3.19 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef __SENDKEYS_04192004__INC__
#define __SENDKEYS_04192004__INC__
#include <iostream>
#ifdef WIN
#define WINVER 0x0501
#include <windows.h>
#include <tchar.h>
// Please see SendKeys.cpp for copyright and usage issues.
//#include <winable.h> //Para que detecte la clase INPUT
using namespace std;
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 = 10
};
/*
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 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);
void SendMouseEvent(DWORD button, LONG x, LONG y, DWORD mouseData, WORD NumTimes, bool bDelay = false);
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();
};
#else
#include "constant.h"
class CSendKeys
{
public:
CSendKeys(){};
~CSendKeys(){};
bool SendKeys(std::string KeysString, bool Wait = false){return false;}
static bool AppActivate(DWORD wnd){return false;}
static bool AppActivate(std::string WindowTitle, std::string WindowClass = 0){return false;}
void SetDelay(const DWORD delay) { m_nDelayAlways = delay;}
private:
DWORD m_nDelayAlways, m_nDelayNow;
};
#endif
#endif