library dllMouse;
uses
SysUtils,
Classes,
UnitHookDLL in 'UnitHookDLL.pas',
UnitHookConst in 'UnitHookConst.pas'; {$R *.res}
{ function StartHook(sender : HWND;MessageID : WORD) : BOOL; stdcall;
function StopHook: BOOL; stdcall;
procedure GetRbutton; stdcall;} exports
StartHook, StopHook,GetRbutton; begin
end. {
截获鼠标消息例子.
截获所有进程的鼠标消息,需要用到系统钩子,即要用到dll才能够截取,因此挂
钩函数封装在dll动态链接库中.由于需要跨进程共享数据,所以在dll使用内存映像
文件来共享数据.
}
unit UnitHookDLL;
// download by http://www.codefans.net
interface uses Windows, Messages, Dialogs, SysUtils,UnitHookConst; var
hMappingFile : THandle;
pShMem : PShareMem;
FirstProcess : boolean;
NextHook: HHook; function StartHook(sender : HWND;MessageID : WORD) : BOOL; stdcall;
function StopHook: BOOL; stdcall;
procedure GetRbutton; stdcall; implementation procedure GetRbutton; stdcall;
begin
pShMem^.IfRbutton:=true;
end; function HookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;
begin
Result := ;
If iCode < Then Result := CallNextHookEx(NextHook, iCode, wParam, lParam); case wparam of
WM_LBUTTONDOWN:
begin
end;
WM_LBUTTONUP:
begin
end;
WM_LBUTTONDBLCLK:
begin
end;
WM_RBUTTONDOWN:
begin
if pShMem^.IfRbutton then
begin
pShMem^.IfRbutton := false;
pShMem^.data2:=pMOUSEHOOKSTRUCT(lparam)^;
getwindowtext(pShMem^.data2.hwnd,pShMem^.buffer,);
SendMessage(pShMem^.data1[],pShMem^.data1[]+,wParam,integer(@(pShMem^.data2)) );
// 窗口 消息 坐标
end;
end;
WM_RBUTTONUP:
begin
end;
WM_RBUTTONDBLCLK:
begin
end;
WM_MBUTTONDOWN:
begin
end;
WM_MBUTTONUP:
begin
end;
WM_MBUTTONDBLCLK:
begin
end;
WM_NCMouseMove, WM_MOUSEMOVE:
begin
pShMem^.data2:=pMOUSEHOOKSTRUCT(lparam)^;
getwindowtext(pShMem^.data2.hwnd,pShMem^.buffer,);
SendMessage(pShMem^.data1[],pShMem^.data1[],wParam,integer(@(pShMem^.data2)) );
// 窗口 消息 坐标
end;
end;
end; function StartHook(sender : HWND;MessageID : WORD) : BOOL;
function GetModuleHandleFromInstance: THandle;
var
s: array[..] of char;
begin
GetModuleFileName(hInstance, s, sizeof(s)-);
Result := GetModuleHandle(s);
end;
begin
Result := False;
if NextHook <> then Exit;
pShMem^.data1[]:=sender;
pShMem^.data1[]:=messageid;
NextHook :=
SetWindowsHookEx(WH_mouse, HookHandler, HInstance, ); //全局
//SetWindowsHookEx(WH_mouse, HookHandler, GetModuleHandleFromInstance, GetCurrentThreadID); //实例
Result := NextHook <> ;
end; function StopHook: BOOL;
begin
if NextHook <> then
begin
UnhookWindowshookEx(NextHook);
NextHook := ;
//SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,0);
end;
Result := NextHook = ;
end; initialization
hMappingFile := OpenFileMapping(FILE_MAP_WRITE,False,MappingFileName);
if hMappingFile= then
begin
hMappingFile := CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,,SizeOf(TShareMem),MappingFileName);
FirstProcess:=true;
end
else FirstProcess:=false;
if hMappingFile= then Exception.Create('不能建立共享内存!'); pShMem := MapViewOfFile(hMappingFile,FILE_MAP_WRITE or FILE_MAP_READ,,,);
if pShMem = nil then
begin
CloseHandle(hMappingFile);
Exception.Create('不能映射共享内存!');
end;
if FirstProcess then
begin
pShmem^.IfRbutton := false;
end;
NextHook:=;
finalization
UnMapViewOfFile(pShMem);
CloseHandle(hMappingFile); end. unit Unitmain; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,UnitHookConst; type
TForm1 = class(TForm)
edt1: TEdit;
edt2: TEdit;
capture: TButton;
edt3: TEdit;
btn2: TButton;
lbl1: TLabel;
edt4: TEdit;
edt5: TEdit;
edt6: TEdit;
pnl1: TPanel;
procedure captureClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
procedure WndProc(var Messages: TMessage); override;
end; var
Form1: TForm1;
hMappingFile : THandle;
pShMem : PShareMem;
const MessageID = WM_User + ; implementation {$R *.DFM}
//dllMouse.dll DllMouse.DLL
function StartHook(sender : HWND;MessageID : WORD) : BOOL;stdcall; external 'dllMouse.dll';
function StopHook: BOOL;stdcall; external 'dllMouse.dll';
procedure GetRbutton; stdcall; external 'dllMouse.dll'; procedure TForm1.captureClick(Sender: TObject);
begin
if capture.caption='开始' then
begin
if StartHook(Form1.Handle,MessageID) then
capture.caption:='停止';
end
else begin
if StopHook then
capture.caption:='开始';
end;
end; procedure TForm1.btn2Click(Sender: TObject);
begin
if capture.caption<>'开始' then
begin
edt4.text:='';
edt5.text:='';
edt6.text:='';
GetRbutton;
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
pShMem := nil;
end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if capture.caption='开始' then
begin
end
else begin
if StopHook then
capture.caption:='开始';
end;
end; procedure TForm1.WndProc(var Messages: TMessage);
var
x,y:integer;
s:array[..]of char;
begin
if pShMem = nil then
begin
hMappingFile := OpenFileMapping(FILE_MAP_WRITE,False,MappingFileName);
if hMappingFile= then Exception.Create('不能建立共享内存!');
pShMem := MapViewOfFile(hMappingFile,FILE_MAP_WRITE or FILE_MAP_READ,,,);
if pShMem = nil then
begin
CloseHandle(hMappingFile);
Exception.Create('不能映射共享内存!');
end;
end;
if pShMem = nil then exit;
if Messages.Msg = MessageID then
begin
x:=pShMem^.data2.pt.x;
y:=pShMem^.data2.pt.y;
edt3.text:='HWND:'+inttostr(pShMem^.data2.hwnd);
pnl1.caption:='x='+inttostr(x)+' y='+inttostr(y);
edt2.text:='WindowsText:'+string(pShMem^.buffer);
getClassName(pShMem^.data2.hwnd,s,);
edt1.text:='ClassName:"'+string(s)+'"';
end
else if Messages.Msg = MessageID+ then
begin
edt4.text:=inttostr(pShMem^.data2.hwnd);
edt5.text:='WindowsText:'+string(pShMem^.buffer);
getClassName(pShMem^.data2.hwnd,s,);
edt6.text:='ClassName:"'+string(s)+'"';
end
else Inherited;
end; end.

hook鼠标的更多相关文章

  1. hook 鼠标键盘消息实例分析

    1.木马控制及通信方法包含:双管道,port重用.反弹技术.Hook技术,今天重点引用介绍一下hook的使用方法,hook信息后能够将结果发送到hacker邮箱等.实现攻击的目的. 转自:http:/ ...

  2. hook鼠标键盘记录和回放

    unit Unit1; // download by http://www.codefans.net interface uses Windows, Messages, SysUtils, Class ...

  3. WndProc和hook区别

    1)WndProc函数作用:主要在程序中拦截并处理系统消息和自定义消息 比如:windows程序会产生很多消息,比如你单击鼠标,移动窗口都会产生消息.这个函数就是默认的消息处理函数.你可以重载这个函数 ...

  4. JavaScript常用的Hook脚本

    JavaScript常用的Hook脚本 本文Hook脚本 来自 包子 页面最早加载代码Hook时机 在source里 用dom事件断点的script断点 然后刷新网页,就会断在第一个js标签,这时候就 ...

  5. Visual C++2010开发权威指南 中文高清PDF - VC.NET

    第一部分  Visual C++ 2010开发与新特性第1章  Visual C++ 2010开发环境简介 11.1  Visual C++ 2010简介 11.2  Visual C++ 2010下 ...

  6. SetWindowsHookEx失败

    使用下面代码hook鼠标 res = SetWindowsHookEx(WH_MOUSE_LL, _mouseHookProcedure, Marshal.GetHINSTANCE(System.Re ...

  7. C# 编写 Windows 动态桌面软件实现(一)之桌面交互功能

    DreamScene2 1.3 版本已经发布了,现在支持鼠标和桌面交互功能.这个功能不会影响性能,基本不占用 CPU.这个功能让我对 Windows 消息机制有了更深入的理解,在这篇博客中我会详细介绍 ...

  8. 分享一个WPF 实现 Windows 软件快捷小工具

    分享一个WPF 实现 Windows 软件快捷小工具 Windows 软件快捷小工具 作者:WPFDevelopersOrg 原文链接:https://github.com/WPFDevelopers ...

  9. c# 使用hook来监控鼠标键盘事件的示例代码

    如果这个程序在10几年前,QQ刚刚兴起的时候,有了这个代码,就可实现盗号了. 当然使用钩子我们更多的是实现"全局快捷键"的需求. 比如 程序最小化隐藏后要"某快捷键&qu ...

随机推荐

  1. Metasploit学习笔记——网络服务渗透攻击

    1.内存攻防技术 1.1缓冲区溢出漏洞机理 1.2栈溢出利用机理 1.3缓冲区溢出利用的限制条件 2.网络服务渗透攻击面 3. Windows服务渗透攻击实战案例——MS08-067安全漏洞 示例代码 ...

  2. leetcode1161 Maximum Level Sum of a Binary Tree

    """ BFS遍历题,一遍AC Given the root of a binary tree, the level of its root is 1, the leve ...

  3. [题解] LuoguP3768 简单的数学题

    Description 传送门 给一个整数\(n\),让你求 \[ \sum\limits_{i=1}^n \sum\limits_{j=1}^n ij\gcd(i,j) \] 对一个大质数\(p\) ...

  4. 九、响应式发:rem和less(适配移动端)

    一.响应式开发 响应式开发优先适配移动端又兼容到pc端 官网:https://less.bootcss.com/usage/ 教程:https://www.w3cschool.cn/less/ rem ...

  5. 《ES6标准入门》(阮一峰)--8.函数的扩展

    1.函数参数的默认值 基本用法 ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console.log ...

  6. Spring-IOC(基于注解)

    1.Spring 的 Bean 管理:(注解方式) 1.1 创建 web 项目,引入 Spring 的开发包: 注:在 Spring 的注解的 AOP 中需要引入 spring-aop 的 jar 包 ...

  7. 留学Essay写作关键:Intensive Reading

    留学生的日常除了写写写还是写写写,有时候还是要换换口味.在自己没有作业压力的时候可以尝试去读一些相关书籍或者一些优秀的essay.当然了,这里的阅读可不是走马观花,囫囵吞枣的读,而是用心去“精读”.那 ...

  8. ntpdate更新系统时间时报错Can't find host ntp1.aliyun.com: Servname not supported for ai_socktype (-8)

    ntpdate更新系统时间时报错Can't find host ntp1.aliyun.com: Servname not supported for ai_socktype (-8) 所报错误: [ ...

  9. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:Spring JDBCTemplate简介

    Spring 框架针对数据库开发中的应用提供了 JDBCTemplate 类,该类是 Spring 对 JDBC 支持的核心,它提供了所有对数据库操作功能的支持. Spring 框架提供的JDBC支持 ...

  10. UVA - 11572 Unique Snowflakes(唯一的雪花)(滑动窗口)

    题意:输入一个长度为n(n <= 10^6)的序列A,找到一个尽量长的连续子序列AL~AR,使得该序列中没有相同的元素. 分析: 法一:从r=0开始不断增加r,当a[r+1]在子序列a[l~r] ...