-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput-hooker-dll.cpp
More file actions
43 lines (38 loc) · 1.04 KB
/
input-hooker-dll.cpp
File metadata and controls
43 lines (38 loc) · 1.04 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
#include "input-hooker-dll.h"
#include <iostream>
Keypressed_t onKeyPressed;
Mouse_t onMouse;
HHOOK keyboardHook = NULL;
HHOOK mouseHook = NULL;
extern "C" __declspec(dllexport)
void __cdecl setCallbacks(Keypressed_t& k, Mouse_t& m, HHOOK kh, HHOOK mh)
{
onKeyPressed = k;
onMouse = m;
keyboardHook = kh;
mouseHook = mh;
}
__declspec(dllexport)
LRESULT __stdcall keyboardCallback(
_In_ int nCode,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
if (nCode >= 0 && onKeyPressed) try {
onKeyPressed(wParam, *reinterpret_cast<KBDLLHOOKSTRUCT*>(lParam));
} catch (...) {/*too late to handle here*/}
return CallNextHookEx(keyboardHook, nCode, wParam, lParam);
}
__declspec(dllexport)
LRESULT __stdcall mouseCallback(
_In_ int nCode,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
if (nCode >= 0 && onMouse) try {
onMouse(wParam, *reinterpret_cast<MSLLHOOKSTRUCT*>(lParam));
} catch (...) {/*too late to handle here*/ }
return CallNextHookEx(mouseHook, nCode, wParam, lParam);
}