能力值:
( LV5,RANK:60 )
|
-
-
2 楼
全局钩子需要用DLL来实现,以前做过一两个,现在也忘了~~
|
能力值:
( LV4,RANK:50 )
|
-
-
3 楼
你的KbdLLProc传进来的参数有线程ID
TranslateMessage
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
给楼主参考。。。
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
HHOOK g_hLLKeyboardHook = NULL;
#ifdef WH_KEYBOARD_LL
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
CHAR szDebug[256];
if (nCode == HC_ACTION)
{
PKBDLLHOOKSTRUCT pKeyboardHookStruct = (PKBDLLHOOKSTRUCT) lParam;
if ((wParam == WM_KEYDOWN) || (wParam == WM_SYSKEYDOWN))
{
BYTE KeyboardState[256];
ZeroMemory(KeyboardState, sizeof(KeyboardState));
GetKeyboardState(KeyboardState);
KeyboardState[VK_SHIFT] = (BYTE) (GetKeyState(VK_LSHIFT) | GetKeyState(VK_RSHIFT));
KeyboardState[VK_CAPITAL] = (BYTE) GetKeyState(VK_CAPITAL);
WORD wChar;
int iNumChar = ToAscii(pKeyboardHookStruct->vkCode, pKeyboardHookStruct->scanCode, KeyboardState, &wChar, 0);
if (iNumChar >= 1)
{
_snprintf(szDebug, 255, "%c", wChar);
OutputDebugString(szDebug);
}
if (iNumChar <= 0)
{
CHAR KeyText[20];
ZeroMemory(KeyText, sizeof(KeyText));
LONG Flags = 0;
Flags = pKeyboardHookStruct->scanCode << 16;
Flags |= pKeyboardHookStruct->flags << 24;
if (GetKeyNameText(Flags, KeyText, 20) > 0)
{
_snprintf(szDebug, 255, "%s", KeyText);
OutputDebugString(szDebug);
}
}
}
}
return CallNextHookEx(g_hLLKeyboardHook, nCode, wParam, lParam);
}
#endif
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
g_hLLKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC) LowLevelKeyboardProc, GetModuleHandle(NULL), 0);
if (g_hLLKeyboardHook == NULL)
{
return -1;
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnhookWindowsHookEx(g_hLLKeyboardHook);
return msg.wParam;
}
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
你好,呵呵。
请问一下,哪个参数给线程ID了啊?
|
能力值:
( LV2,RANK:10 )
|
-
-
6 楼
谢谢哥们,这可是相当的好使啊~~~
|
|
|