C++ hook 问题
检测键盘,有按键就cout<<“按键了”。应该是怎么个流程??要不要自己写个DLL?然后用程序加载或注入?我知道用什么函数,但是返回的句柄老是0。...
检测键盘,有按键就cout<<“按键了”。
应该是怎么个流程??
要不要自己写个DLL?然后用程序加载或注入?
我知道用什么函数,但是返回的句柄老是0。 展开
应该是怎么个流程??
要不要自己写个DLL?然后用程序加载或注入?
我知道用什么函数,但是返回的句柄老是0。 展开
2个回答
展开全部
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
// function declaration.
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam );
int main()
{
// Retrieve the applications instance
HINSTANCE appInstance = GetModuleHandle(NULL);
// Set a global Windows Hook to capture keystrokes.
SetWindowsHookEx( WH_KEYBOARD_LL, LowLevelKeyboardProc, appInstance, 0 );
MSG msg;
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )
{
// Declare our pointer to the KBDLLHOOKSTRUCT
KBDLLHOOKSTRUCT *pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
switch( wParam )
{
case WM_KEYUP: // When the key has been pressed and released
{
switch( pKeyBoard->vkCode ) // Check to see what key has been pushed
{
case VK_RETURN: // The return/enter key has been pressed
DWORD timestamp = pKeyBoard->time; // This shows our timestamp when the key was pushed.
printf("Enter Key Pressed %u", timestamp ); // Show us when the key has been pushed
break;
}
}
default:
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
return 0;
}
#include <stdio.h>
#include <tchar.h>
// function declaration.
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam );
int main()
{
// Retrieve the applications instance
HINSTANCE appInstance = GetModuleHandle(NULL);
// Set a global Windows Hook to capture keystrokes.
SetWindowsHookEx( WH_KEYBOARD_LL, LowLevelKeyboardProc, appInstance, 0 );
MSG msg;
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )
{
// Declare our pointer to the KBDLLHOOKSTRUCT
KBDLLHOOKSTRUCT *pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
switch( wParam )
{
case WM_KEYUP: // When the key has been pressed and released
{
switch( pKeyBoard->vkCode ) // Check to see what key has been pushed
{
case VK_RETURN: // The return/enter key has been pressed
DWORD timestamp = pKeyBoard->time; // This shows our timestamp when the key was pushed.
printf("Enter Key Pressed %u", timestamp ); // Show us when the key has been pushed
break;
}
}
default:
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询