用Delphi写的低级键盘钩子!
<P>implementation</P><P>uses IniOper, TMain;
//-----------------------------------------------------------------
type
LPByte=PByte;
PKBDLLHOOKSTRUCT =^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT=record
vkCode: DWORD;
scanCode:DWORD;
flags:DWORD;
time:DWORD;
dwExtraInfDWORD;
end;
const
LLKHF_ALTDOWN=KF_ALTDOWN shr 8;
WH_KEYBOARD_LL=13;
var
hhkNTKeyboard: HHOOK;
function TSysOper.GetWinVer:Byte;//获取windows操作系统的版本
var
OS:TOSVersionInfo;
begin
Result:=0;
OS.dwOSVersionInfoSize:=SizeOf(TOSVersionInfo);
GetVersionEx(OS);
case OS.dwPlatformId of
VER_PLATFORM_WIN32s : Result:=0;//Windows 3.1x/32s
VER_PLATFORM_WIN32_WINDOWS : Result:=1;//Windows95
VER_PLATFORM_WIN32_NT : Result:=2;//Windows NT
end;
end;
function LowLevelKeyboardFunc(nCode:Integer;w_Param:WPARAM;l_Param:LPARAM):LRESULT;stdcall;
var
blEatKeystroke:Boolean;
P:PKBDLLHOOKSTRUCT;
begin
blEatKeystroke:=false;
if nCode=HC_ACTION then
begin
case w_Param of
WM_KEYDOWN,
WM_SYSKEYDOWN,
WM_KEYUP,
WM_SYSKEYUP:
begin
P:=PKBDLLHOOKSTRUCT(l_Param);
blEatKeystroke:=(((p^.vkCode=VK_TAB) and
((p^.flags and LLKHF_ALTDOWN)<>0)) or
(p^.vkCode=VK_LWIN) or
(p^.vkCode=VK_RWIN) or
((p^.vkCode=VK_ESCAPE) and
((p^.flags and LLKHF_ALTDOWN)<>0)) or
((p^.vkCode=VK_ESCAPE) and
((GetKeyState(VK_CONTROL) and $8000)<>0)) or
((p^.vkCode=VK_DELETE) and
((p^.flags and LLKHF_ALTDOWN)<>0) and
((GetKeyState(VK_CONTROL) and $8000)<>0)));
end;
end;
end;
if blEatKeystroke then
begin
Result:=1;
end
else
Result:=CallNextHookEx(0,nCode,w_Param,l_Param);
end;</P>
<P>function TSysOper.LoadHook():Boolean;
var
Temp:Integer;
begin
Result:=false;
if GetWinVer=2 then
begin
hhkNTKeyboard:= SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardFunc,HInstance,0);
if hhkNTKeyboard=0 then
Result:=false
else
Result:=true;
end
else
begin
SystemParametersInfo(SPI_SCREENSAVERRUNNING,1,@Temp,1);
Result:=true;
end;
end;</P> ..................................
static/image/common/sigline.gif
51koo.net黑客论坛 soyangsyl.com搜羊娱乐新闻网 您好!想要详细了解可以打我电话18321366337 或者加我QQ395260158
页:
[1]