-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhooking.cpp
84 lines (65 loc) · 2.33 KB
/
hooking.cpp
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
#include <Windows.h>
HINSTANCE hInst;
HWND list;
LRESULT CALLBACK LowLevelKeyboardProc1(int code, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
HHOOK hhook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)LowLevelKeyboardProc1, hInst, 0);
LRESULT CALLBACK LowLevelKeyboardProc1(int code, WPARAM wParam, LPARAM lParam) {
//MessageBox(NULL, L"START", L"KEY", MB_OK);
if ((code == HC_ACTION) &&
((wParam == WM_SYSKEYDOWN) || (wParam == WM_KEYDOWN))) // Å° ÀÔ·ÂÀ̸é
{
KBDLLHOOKSTRUCT hooked = *((KBDLLHOOKSTRUCT*)lParam);
TCHAR lpszName[256];
DWORD dwMsg = 1;
dwMsg += hooked.scanCode << 16; // ASCII ÄÚµå º¯È¯
dwMsg += hooked.flags << 24;
GetKeyNameText(dwMsg, (lpszName), 256);
//wchar_t lpszName[10];
//memset(lpszName, 0, 256);
//wsprintf(lpszName, L"%d", hooked.scanCode);
SendMessage(list, LB_ADDSTRING, 0, (LPARAM)lpszName);
//MessageBox(NULL,lpszName,L"KEY",MB_OK);
}
return CallNextHookEx(hhook, code, wParam, lParam);
}
LPCWSTR lpszClass = TEXT("HookTest");
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance
, LPSTR lpszCmdParam, int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
hInst = hInstance;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = (WNDPROC)WndProc;
WndClass.lpszClassName = lpszClass;
WndClass.lpszMenuName = NULL;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd = CreateWindow(lpszClass, lpszClass, WS_OVERLAPPEDWINDOW,
0, 0, 200, 500,
NULL, (HMENU)NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
while (GetMessage(&Message, 0, 0, 0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch (Message) {
case WM_CREATE:
list = CreateWindow(L"listbox", NULL, WS_VISIBLE | WS_VSCROLL | WS_CHILD | WS_BORDER | LBS_NOTIFY, 0, 0, 200, 400, hWnd, (HMENU)0, hInst, NULL);
SendMessage(list, LB_ADDSTRING, 0, (LPARAM)L"Start");
break;
case WM_DESTROY:
PostQuitMessage(0);
}
return(DefWindowProc(hWnd, Message, wParam, lParam));
}