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
|
#include "includes.h"
HHOOK hHookKB2=NULL;
// install low level keyboard hook
int SetHook()
{
int err = 0;
hHookKB2 = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)LowLevelKeyboardProc, GetModuleHandle( NULL ),0);
if(hHookKB2==NULL)
{
err = (int)GetLastError();
return err;
}
return 0;
}
// remove low level keyboard hook
int RemoveHook()
{
BOOL Hbool = 0;
int err = 0;
Hbool = UnhookWindowsHookEx(hHookKB2);
if(Hbool == 0)
{
err = (int)GetLastError();
return err;
}
return 0;
}
// this function is called by windows if a key is pressed
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
KBDLLHOOKSTRUCT *kbdl_struct;
if(nCode != HC_ACTION){
return ( CallNextHookEx(hHookKB2, nCode, wParam, lParam) );
}
kbdl_struct = (KBDLLHOOKSTRUCT*) lParam;
if(KeyBuddy2::ProcessKbdEvent(
wParam,
kbdl_struct->vkCode,
kbdl_struct->scanCode,
(kbdl_struct->flags & LLKHF_EXTENDED) !=0,
(kbdl_struct->flags & LLKHF_INJECTED) !=0,
(kbdl_struct->flags & LLKHF_ALTDOWN) !=0,
(kbdl_struct->flags & LLKHF_UP) !=0,
kbdl_struct->dwExtraInfo))
{
return ( CallNextHookEx(hHookKB2, nCode, wParam, lParam) );
}
else
{
return 1;
}
}
|