[笨嘴拙舌WINDOWS]实践检验之按键精灵[Delphi]

【笨嘴拙舌WINDOWS】实践检验之按键精灵【Delphi】

通过记录键盘和鼠标位置和输入信息,然后模拟发送,就能够创建一个按键精灵!

主要代码如下:

1 library KeyBoardHook; 2 3 { Important note about DLL memory management: ShareMem must be the 4 first unit in your library's USES clause AND your project's (select 5 Project-View Source) USES clause if your DLL exports any procedures or 6 functions that pass strings as parameters or function results. This 7 applies to all strings passed to and from your DLL--even those that 8 are nested in records and classes. ShareMem is the interface unit to 9 the BORLNDMM.DLL shared memory manager, which must be deployed along10 with your DLL. To avoid using BORLNDMM.DLL, pass string information11 using PChar or ShortString parameters. }12 13 uses14 SysUtils,15 Classes,16 Windows,17 Messages;18 19 type20 TCallBackFun=procedure(info:PChar);21 TKeyBoardHook=record22 isrun:Bool;23 hook:HHook;24 callBackFun:TCallBackFun;25 end;26 27 var28 myKeyBoardHook:TKeyBoardHook;29 {$R *.res}30 31 function GetKeyBoardInfo(code:Integer;wp:WPARAM;lp:LPARAM):LRESULT;stdcall;32 var33 info:string;34 begin35 if code

以上是创建一个全局钩子函数的Dll来记录按键信息

library Mousehook;{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }uses SysUtils, Classes, Windows, Messages, ShellAPI; type TCallbackFun=procedure(info:pchar); TMouseHook=record isrun:Bool; hook:HHook; callbackFun:TCallbackFun; end;var myMouseHook:TMouseHook;{$R *.res}//1.定义自定义的HOOK函数,函数必须和需要HOOK的钩子类型保持同样的参数列表function GetHookInfo(code:Integer;wp:WPARAM;lp:LPARAM):LResult;stdcall;var info:String;begin if code

以上是捕获鼠标消息的全局钩子DLL

使用一个新的线程来模拟发送消息

procedure TPlayThread.Execute;var directive:string; i:integer; ForgroundForm:TForm; procedure ExecuteDir(directive:string); var tempList:TStringList; Wp,Lp:integer; wmtype:String; focusControl:string; duration:Cardinal; winCtl:TWinControl; tempHandle,focusHandle:THandle; classname:String; mousPoint:TPOINT; procedure findFocus; var temp:TWinControl; finded:Boolean; begin if ((wmtype='WM_MOUSEMOVE') or (wmtype='WM_NCMouseMove')) then Exit; winCtl:=TWinControl(ForgroundForm.FindChildControl(focusControl)); if winCtlnil then begin focusHandle:= winCtl.Handle; AttachThreadInput(GetWindowThreadProcessId(ForgroundForm.Handle,nil),Self.ThreadID,True); Ferrorinfo:=SysErrorMessage(GetLastError); winCtl.SetFocus; AttachThreadInput(GetWindowThreadProcessId(ForgroundForm.Handle,nil),Self.ThreadID,False); Ferrorinfo:=SysErrorMessage(GetLastError); Exit; end; temp:=nil; finded:=False; while not finded do begin GetCursorPos(mousPoint); tempHandle := WindowFromPoint(mousPoint); if tempHandle =0 then begin Sleep(0); Continue; end; temp:=FindControl(tempHandle); if temp=nil then begin Sleep(0); Continue; end; if (temp.Name = focusControl) or (classname=temp.ClassName) then finded:=True; end; focusHandle := temp.Handle; AttachThreadInput(GetWindowThreadProcessId(ForgroundForm.Handle,nil),Self.ThreadID,True); Ferrorinfo:=SysErrorMessage(GetLastError); temp.SetFocus; AttachThreadInput(GetWindowThreadProcessId(ForgroundForm.Handle,nil),Self.ThreadID,False); Ferrorinfo:=SysErrorMessage(GetLastError); end; begin tempList:=TStringList.Create; try tempList.CommaText:=directive; tempList.Delimiter:=','; wmtype:=tempList[0]; focusHandle:=0; Wp:=StrToIntDef(tempList[1],0); //wParam Lp:=StrToIntDef(tempList[2],0); //Lparam duration:= StrToIntDef(tempList[3],0); if (duration=0) and (wmtype='WM_NCMouseMove') then Exit; //小于线程调度时间片的话就不延时---以免 sleep(0)直接放弃时间进入内核态 if (wmtype='') or (tempList.Count

点击这里下载代码

分类: WINDOWS地基

绿色通道:好文要顶关注我收藏该文与我联系

Pavkoo

关注 - 1

粉丝 - 7

+加关注

0

0

(请您对文章做出评价)

? 上一篇:【笨嘴拙舌WINDOWS】键盘消息,鼠标消息

? 下一篇:【笨嘴拙舌WINDOWS】计时器精度

posted @ 2013-09-12 11:48 Pavkoo 阅读(95) 评论(0) 编辑 收藏

刷新评论刷新页面返回顶部

注册用户登录后才能发表评论,请 登录 或 注册,访问网站首页。

博客园首页博问新闻闪存程序员招聘知识库

最新IT新闻:

· 看互联巨头table的投资万象

· GoPro上线视频交易平台,要开始在内容上挣点钱了

· eBay分拆PayPal背后有什么故事

· 京东的麻烦:成长烦恼or中年危机?

· 如何建立企业文化,看前Facebook高管给创业者提供的几点干货

? 更多新闻...

最新知识库文章:

· RESTful架构详解

· 优秀程序员眼中的整洁代码

· 怎样看待比自己强的人

· 编程王道,唯“慢”不破

· 程序员要有持续产出

? 更多知识库文章...

历史上的今天:

2010-09-12 Asp.net高级程序设计之WEB窗体(3)

公告

昵称:Pavkoo

园龄:5年2个月

粉丝:7

关注:1+加关注

日一二三四五六

2829301234

567891011

[1**********]718

[1**********]425

[1**********]11

2345678

搜索

【笨嘴拙舌WINDOWS】实践检验之按键精灵【Delphi】

通过记录键盘和鼠标位置和输入信息,然后模拟发送,就能够创建一个按键精灵!

主要代码如下:

1 library KeyBoardHook; 2 3 { Important note about DLL memory management: ShareMem must be the 4 first unit in your library's USES clause AND your project's (select 5 Project-View Source) USES clause if your DLL exports any procedures or 6 functions that pass strings as parameters or function results. This 7 applies to all strings passed to and from your DLL--even those that 8 are nested in records and classes. ShareMem is the interface unit to 9 the BORLNDMM.DLL shared memory manager, which must be deployed along10 with your DLL. To avoid using BORLNDMM.DLL, pass string information11 using PChar or ShortString parameters. }12 13 uses14 SysUtils,15 Classes,16 Windows,17 Messages;18 19 type20 TCallBackFun=procedure(info:PChar);21 TKeyBoardHook=record22 isrun:Bool;23 hook:HHook;24 callBackFun:TCallBackFun;25 end;26 27 var28 myKeyBoardHook:TKeyBoardHook;29 {$R *.res}30 31 function GetKeyBoardInfo(code:Integer;wp:WPARAM;lp:LPARAM):LRESULT;stdcall;32 var33 info:string;34 begin35 if code

以上是创建一个全局钩子函数的Dll来记录按键信息

library Mousehook;{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }uses SysUtils, Classes, Windows, Messages, ShellAPI; type TCallbackFun=procedure(info:pchar); TMouseHook=record isrun:Bool; hook:HHook; callbackFun:TCallbackFun; end;var myMouseHook:TMouseHook;{$R *.res}//1.定义自定义的HOOK函数,函数必须和需要HOOK的钩子类型保持同样的参数列表function GetHookInfo(code:Integer;wp:WPARAM;lp:LPARAM):LResult;stdcall;var info:String;begin if code

以上是捕获鼠标消息的全局钩子DLL

使用一个新的线程来模拟发送消息

procedure TPlayThread.Execute;var directive:string; i:integer; ForgroundForm:TForm; procedure ExecuteDir(directive:string); var tempList:TStringList; Wp,Lp:integer; wmtype:String; focusControl:string; duration:Cardinal; winCtl:TWinControl; tempHandle,focusHandle:THandle; classname:String; mousPoint:TPOINT; procedure findFocus; var temp:TWinControl; finded:Boolean; begin if ((wmtype='WM_MOUSEMOVE') or (wmtype='WM_NCMouseMove')) then Exit; winCtl:=TWinControl(ForgroundForm.FindChildControl(focusControl)); if winCtlnil then begin focusHandle:= winCtl.Handle; AttachThreadInput(GetWindowThreadProcessId(ForgroundForm.Handle,nil),Self.ThreadID,True); Ferrorinfo:=SysErrorMessage(GetLastError); winCtl.SetFocus; AttachThreadInput(GetWindowThreadProcessId(ForgroundForm.Handle,nil),Self.ThreadID,False); Ferrorinfo:=SysErrorMessage(GetLastError); Exit; end; temp:=nil; finded:=False; while not finded do begin GetCursorPos(mousPoint); tempHandle := WindowFromPoint(mousPoint); if tempHandle =0 then begin Sleep(0); Continue; end; temp:=FindControl(tempHandle); if temp=nil then begin Sleep(0); Continue; end; if (temp.Name = focusControl) or (classname=temp.ClassName) then finded:=True; end; focusHandle := temp.Handle; AttachThreadInput(GetWindowThreadProcessId(ForgroundForm.Handle,nil),Self.ThreadID,True); Ferrorinfo:=SysErrorMessage(GetLastError); temp.SetFocus; AttachThreadInput(GetWindowThreadProcessId(ForgroundForm.Handle,nil),Self.ThreadID,False); Ferrorinfo:=SysErrorMessage(GetLastError); end; begin tempList:=TStringList.Create; try tempList.CommaText:=directive; tempList.Delimiter:=','; wmtype:=tempList[0]; focusHandle:=0; Wp:=StrToIntDef(tempList[1],0); //wParam Lp:=StrToIntDef(tempList[2],0); //Lparam duration:= StrToIntDef(tempList[3],0); if (duration=0) and (wmtype='WM_NCMouseMove') then Exit; //小于线程调度时间片的话就不延时---以免 sleep(0)直接放弃时间进入内核态 if (wmtype='') or (tempList.Count

点击这里下载代码

分类: WINDOWS地基

绿色通道:好文要顶关注我收藏该文与我联系

Pavkoo

关注 - 1

粉丝 - 7

+加关注

0

0

(请您对文章做出评价)

? 上一篇:【笨嘴拙舌WINDOWS】键盘消息,鼠标消息

? 下一篇:【笨嘴拙舌WINDOWS】计时器精度

posted @ 2013-09-12 11:48 Pavkoo 阅读(95) 评论(0) 编辑 收藏

刷新评论刷新页面返回顶部

注册用户登录后才能发表评论,请 登录 或 注册,访问网站首页。

博客园首页博问新闻闪存程序员招聘知识库

最新IT新闻:

· 看互联巨头table的投资万象

· GoPro上线视频交易平台,要开始在内容上挣点钱了

· eBay分拆PayPal背后有什么故事

· 京东的麻烦:成长烦恼or中年危机?

· 如何建立企业文化,看前Facebook高管给创业者提供的几点干货

? 更多新闻...

最新知识库文章:

· RESTful架构详解

· 优秀程序员眼中的整洁代码

· 怎样看待比自己强的人

· 编程王道,唯“慢”不破

· 程序员要有持续产出

? 更多知识库文章...

历史上的今天:

2010-09-12 Asp.net高级程序设计之WEB窗体(3)

公告

昵称:Pavkoo

园龄:5年2个月

粉丝:7

关注:1+加关注

日一二三四五六

2829301234

567891011

[1**********]718

[1**********]425

[1**********]11

2345678

搜索


相关内容

  • 高校信息管理系统
  • 附录二 软件设计范例 本附录以"高校信息管理系统"为实例,给出软件开发过程中的有关要求和所涉及的文档,介绍了软件设计的基本过程和方法.通过介绍的软件设计开发示例过程和范例文档,读者可以在软件设计和文档编写中进行参考.软件设计开发各阶段的主要任务及方法请参考书中相关章节,这里不再赘 ...

  • 软件开发界面规范技巧和注意事项
  • 界面规范 一:遵循一致的准则,确立标准并遵循 无论是控件使用,提示信息措辞,还是颜色.窗口布局风格,遵循统一的标准,做到真正的一致. 这样得到的好处: 1:使用户使用起来能够建立起精确的心里模型,使用熟练了一个界面后,切换到另外一个界面能够很轻松的推测出各种功能,语句理解也不需要费神理解 2:降低培 ...

  • [热血江湖]攻略:骗术及小木马集合
  • <热血江湖>攻略:骗术及小木马集合 骗装备:首先大街上迎面跑来一帅哥或靓女,直接问你哥哥[姐姐或朋友.兄弟.姐妹啥滴]看看你的武器,一般爱炫的朋友和热心的朋友容易上当,拿出来北,想看就看[要看得漂亮]. 把武器拿到装备栏,给他看,骗子们开始发挥口才了,好厉害,冲成这样了!!!(一般都多说 ...

  • 毕业论文 企业档案管理系统
  • 摘 要 企业员工的档案管理是企业员工管理的一个重要内容.当今社会人员流动越来越频繁,使得档案管理工作也变得越来越复杂.如何管理好企业员工的信息,成为企业管理中一个大的问题.如果能实现档案管理的自动化,无疑将给公司管理部门带来很大的方便. 本论文对企业档案管理系统进行了设计与实现.此系统能够帮助档案管 ...

  • win32下delphi全局钩子的实现的关键技术
  • 自15年前Windows 3.1推出以来,Win32全局钩子的实现始终是32位Windows程序设计中最富挑战性的课题之一.全局钩子可以捕获系统向应用程序发送的消息(比如键盘和鼠标操作.系统设置改变等等),因而被广泛地应用在各种商用应用软件中,其中又以金山词霸的"屏幕取词"功能最 ...

  • 题库系统与试卷生成
  • 摘 要 一般情况教师想出一份试卷,要么到庞大的题库里一道一道的把题找出来,或是从几本相关的书里把题一道一道挑出来.这样即费时又费力,而且很难保证试题的覆盖面和把握好试卷的难度.正是为了能够帮助教师轻松的出一份高质量的试卷而开发了本软件.为了达到预期的目标我们最终选择了Microsoft Office ...

  • 按键精灵-冷血课堂
  • [教程] 冷血课堂1--如何通过读取颜色来"认识"数字? 记得很久以前曾经跟兄弟论坛上的一个朋友说过,猎手确实就是一个读颜色的脚本,根本没有涉及读取内存.不是按键精灵不支持读取内存地址(按键精灵从内存地址中读取一个数字,还是很简单的,一条命令就可以实现),也不是说游戏中的数值多么 ...

  • 谈谈Windows程序中的字符编码(2)
  • 2 Locale和ANSI代码页 2.1 Locale和LCID Locale是指特定于某个国家或地区的一组设定,包括字符集,数字.货币.时间和日期的格式等.在Windows中,每个Locale可以用一个32位数字表示,记作LCID.在winnt.h中可以看到LCID的组成.它的高16位表示字符的排 ...

  • N多毕业设计题目
  • 基于Ajax技术的WEB应用的设计 又快到毕业的时候了,大家该准备做毕业设计了.大学问问特意收集了一些毕业设计(论文)的题目,供大家选择. VB售楼管理系统 VB无纸化考试系统 VB小区物业管理系统 VB航空公司管理信息系统 VB计算机机房管理系统 VB房地产评估系统VB+SQL2000 VB光盘信 ...