http://codeguru.earthweb.com/system/KBHook.html
Hooking the Keyboard - Anoop Thomas (2001/12/13)
This article describes how to install a Keyboard hook in Microsoft Windows.
Hooking the Keyboard - Anoop Thomas (2001/12/13)
This article describes how to install a Keyboard hook in Microsoft Windows.
应该用消息钩子来做。在截获WM_KEYDOWN/WM_KEYUP消息后,可以对这个消息进行改变,但我不能确定是否能发5个消息出去。
#include "window.h"
LRESULT CALLBACK LowLevelKbProc(int nCode,WPARAM wParam,LPARAM lParam)
{
BOOL fEatKeystroke=FALSE;
if(nCode==HC_ACTION)
{
switch(wParam)
{
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
PKBDLLHOOKSTRUCT p=(PKBDLLHOOKSTRUCT)lParam;
fEatKeystroke=((p->vkCode==VK_TAB)&&((p->flags&LLKHF_ALTDOWN)!=0))||
((p->vkCode==VK_ESCAPE)&&((p->flags&LLKHF_ALTDOWN)!=0))||
((p->vkCode==VK_ESCAPE)&&((GetKeyState(VK_CONTROL)&0x8000)!=0)));
break;
}
}return(fEatKeystroke?1:CallNextHookEx(NULL,nCode,wParam,lParam));
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HHOOK hhkLowLevelKybd=SetWindowsHookEx(WH_KEYBOARD_LL,
LowLevelKbProc,hInstance,0);
MessageBox(NULL,
TEXT("Alt+Esc,Ctrl+Esc,and Alt+Tab are now disabled\n"),
TEXT("Click\"OK\"to terminate this application and re_enable these keys."),
TEXT("Disable Low-Level Keys"),MB_OK);
UnhookWindowsHookEx(hhkLowLevelKybd); return 0;
}