我想做一个系统级的钩子,作用就是按一下F12,就执行一下右键,在任何程序中都可以!但不知道什么地方有错误,请大侠们指点一下,代码如下::
// wing12345.cpp : Defines the entry point for the DLL application.
//#include "stdafx.h"
#include "wing12345.h"
HINSTANCE hinstance;
HHOOK wingKey;
BOOL APIENTRY DllMain( HANDLE hModule, 
DWORD ul_reason_for_call, 
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
hinstance=(HINSTANCE)hModule;
return TRUE;
}
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wparam,LPARAM lparam)
{
if(nCode==HC_ACTION)
if(wparam==VK_F12)
{
PostMessage(NULL,VK_RIGHT,0,0);
}
return CallNextHookEx(NULL,nCode,wparam,lparam);
}
WING12345_API BOOL EnableKey()
{
if(!(wingKey=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hinstance,0)))
return FALSE;
return TRUE;
}
WING12345_API BOOL DisableKey()
{
return UnhookWindowsHookEx(wingKey);
}
///////////以上是动态库
/ wingdll.cpp : Defines the entry point for the application.
//#include "stdafx.h"
#include "wing12345.h"
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
if(KEYDOWN(VK_F12))
EnableKey();
if(KEYDOWN(VK_F11))
DisableKey();
return 0;
}////以上为win32程序
我用的是postmessage,还有如何用keybd_event或SendInput请大侠们指点指点!!