hook键盘钩子 带dll
library Key;
uses
SysUtils,
Classes,
HookKey_Unit in 'HookKey_Unit.pas'; {$R *.res} exports
HookOn,HookOff;
begin end. unit HookKey_Unit; interface
uses windows,messages;//Dialogs;
const
WM_HOOKKEY = WM_USER + $;
procedure HookOn; stdcall;
procedure HookOff; stdcall;
implementation
var
HookDeTeclado : HHook;
FileMapHandle : THandle;
PViewInteger : ^Integer; function CallBackDelHook( Code : Integer;
wParam : WPARAM;
lParam : LPARAM
) : LRESULT; stdcall; begin
if code=HC_ACTION then
begin
FileMapHandle:=OpenFileMapping(FILE_MAP_READ,False,'TestHook');
if FileMapHandle<> then
begin
PViewInteger:=MapViewOfFile(FileMapHandle,FILE_MAP_READ,,,);
PostMessage(PViewInteger^,WM_HOOKKEY,wParam,lParam);
//ShowMessage('a');
UnmapViewOfFile(PViewInteger);
CloseHandle(FileMapHandle);
end;
end;
Result := CallNextHookEx(HookDeTeclado, Code, wParam, lParam);
//ShowMessage('b');
end; procedure HookOn; stdcall;
begin
HookDeTeclado:=SetWindowsHookEx(WH_KEYBOARD, CallBackDelHook, HInstance , );
end; procedure HookOff; stdcall;
begin
UnhookWindowsHookEx(HookDeTeclado);
end; end. unit TestHookKey_Unit;
// download by http://www.codefans.net
interface
// download by http://www.codefans.net
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls; const
WM_HOOKKEY= WM_USER + $;
HookDLL = 'Key.dll';
type
THookProcedure=procedure; stdcall;
TForm1 = class(TForm)
mmo1: TMemo;
//Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FileMapHandle : THandle;
PMem : ^Integer;
HandleDLL : THandle;
HookOn,
HookOff : THookProcedure;
procedure HookKey(var message: TMessage); message WM_HOOKKEY; public
{ Public declarations }
end;
var
Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject);
begin
mmo1.ReadOnly:=TRUE;
mmo1.Clear;
HandleDLL:=LoadLibrary( PChar(ExtractFilePath(Application.Exename)+
HookDll) );
if HandleDLL = then raise Exception.Create('未发现键盘钩子DLL');
@HookOn :=GetProcAddress(HandleDLL, 'HookOn');
@HookOff:=GetProcAddress(HandleDLL, 'HookOff');
IF not assigned(HookOn) or
not assigned(HookOff) then
raise Exception.Create('在给定的 DLL中'+#+
'未发现所需的函数'); FileMapHandle:=CreateFileMapping( $FFFFFFFF,
nil,
PAGE_READWRITE,
,
SizeOf(Integer),
'TestHook'); if FileMapHandle= then
raise Exception.Create( '创建内存映射文件时出错');
PMem:=MapViewOfFile(FileMapHandle,FILE_MAP_WRITE,,,);
PMem^:=Handle;
HookOn;
end;
procedure TForm1.HookKey(var message: TMessage);
var
KeyName : array[..] of char;
Accion : string;
begin
GetKeyNameText(Message.LParam,@KeyName,);
if ((Message.lParam shr ) and )=
then Accion:='Key Up'
else
if ((Message.lParam shr ) and )=
then Accion:='ReKeyDown'
else Accion:='KeyDown';
mmo1.Lines.add( Accion+
': '+
String(KeyName)) ;
end; procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(HookOff) then
HookOff;
if HandleDLL<> then
FreeLibrary(HandleDLL);
if FileMapHandle<> then
begin
UnmapViewOfFile(PMem);
CloseHandle(FileMapHandle);
end; end; end.
hook键盘钩子 带dll的更多相关文章
- 基于C#实现的HOOK键盘钩子实例代码
本文所述为基于C#实现的HOOK实例,该实例可用来屏蔽系统热键.程序主要实现了安装钩子.传递钩子.卸载钩子等功能.在传递钩子中:<param name="pHookHandle&quo ...
- hook键盘钩子_非dll
unit Unit1; // download by http://www.codefans.net interface uses Windows, Messages, SysUtils, Class ...
- 在WPF中快速实现键盘钩子
大部分的时候,当我们需要键盘事件的时候,可以通过在主窗口注册KeyBinding来实现,不过,有的时候我们需要的是全局键盘事件,想在任何一个地方都能使用,最开始的时候我是通过键盘钩子来实现的, 不过键 ...
- 2.添加键盘钩子。向进程中注入dll
学习笔记 1.首先要建立mfc的动态链接库.在def文件中放入要导出的函数名. 2.添加函数如下 //安装钩子 //HHOOK SetWindowsHookEx( // int idHook,//钩子 ...
- 钩子编程(HOOK) 安装进程内键盘钩子 (1)
摘要:钩子能够监视系统或进程中的各种事件消息.截获发往目标窗体的消息并进行处理.这样,我们就能够在系统中安装自己定义的钩子,监视系统中特定事件的发生.完毕特定的功能,比方截获键盘.鼠标的输入.屏幕取词 ...
- C#鼠标键盘钩子
using System;using System.Collections.Generic; using System.Reflection; using System.Runtime.Interop ...
- 什么是HOOK(钩子):消息拦截与处理
对于Windows系统,它是建立在事件驱动机制上的,说白了就是整个系统都是通过消息传递实现的.hook(钩子)是一种特殊的消息处理机制,它可以监视系统或者进程中的各种事件消息,截获发往目标窗口的消息并 ...
- Hook(钩子技术)基本知识讲解,原理
一.什么是HOOK(钩子) API Windows消息传递机制,当在应用程序进行相关操作,例如点击鼠标.按下键盘,操作窗口等,操作系统能够感知这一事件,接着把此消息放到系统消息队列,然后到应用程序的 ...
- C# 键盘钩子
p{ text-align:center; } blockquote > p > span{ text-align:center; font-size: 18px; color: #ff0 ...
随机推荐
- numpy.linspace使用详解
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) 在指定的间隔内返回均匀间隔的数字. 返回nu ...
- 挖矿程序minerd入侵分析和解决办法
现在比特币的价格涨得很高,所以现在有黑客专门制造挖矿木马来诱导网友,从而达到控制电脑上的显卡来挖掘比特币.为什么木马要控制电脑中的显卡呢?因为显卡挖掘虚拟货币比特币的效率远比 CPU 要高.如果你是一 ...
- SpringBoot-拦截器配置
SpringBoot-拦截器配置 SpringBoot-拦截器配置 在我们的SSM项目中,可以在web.xml中配置拦截器,但是在SpringBoot中只能使用java类来配置,配置方法如下. 创建拦 ...
- python二维图像输出操作大全(非常全)!
//2019.07.141.matplotlib模块输出函数图像应用时主要用的是它的ptplot模块,因此在导入使用该模块时可以直接用以下语句:import matplotlib.pyplot as ...
- c#使用Socket实现局域网内通信
服务器端代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Da ...
- POJ2533:Longest Ordered Subsequence
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 37454 Acc ...
- MongoDB 3.2 升级至 3.4.6
MongoDB 升级测试步骤:1.MongoDB版本升级顺序3.2->3.4->3.6->4.0 不能跨版本升级2.升级到3.4后,您不能降级到3.2.7或更早版本.您只能降级到3. ...
- 《TensorFlow实战Google深度学习框架》笔记——TensorFlow环境搭建
一.TensorFlow的主要依赖包 1.Protocol Buffer Protocol Buffer负责将结构化的数据序列化,并从序列化之后的数据流中还原出原来的结构化数据.TensorFlow中 ...
- 74.Python中ORM聚合函数详解:Max,Min
Max和Min:获取指定对象的最大值和最小值. 1. 比如:想要获取Author表中的最大的年龄和最小的年龄.示例代码如下: from django.http import HttpResponse ...
- 17.swoole学习笔记--异步mysql操作
<?php //异步mysql操作 $db=new swoole_mysql(); $config=[ 'host'=>'192.168.10.31', 'user'=>'zouke ...