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的更多相关文章

  1. 基于C#实现的HOOK键盘钩子实例代码

    本文所述为基于C#实现的HOOK实例,该实例可用来屏蔽系统热键.程序主要实现了安装钩子.传递钩子.卸载钩子等功能.在传递钩子中:<param name="pHookHandle&quo ...

  2. hook键盘钩子_非dll

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

  3. 在WPF中快速实现键盘钩子

    大部分的时候,当我们需要键盘事件的时候,可以通过在主窗口注册KeyBinding来实现,不过,有的时候我们需要的是全局键盘事件,想在任何一个地方都能使用,最开始的时候我是通过键盘钩子来实现的, 不过键 ...

  4. 2.添加键盘钩子。向进程中注入dll

    学习笔记 1.首先要建立mfc的动态链接库.在def文件中放入要导出的函数名. 2.添加函数如下 //安装钩子 //HHOOK SetWindowsHookEx( // int idHook,//钩子 ...

  5. 钩子编程(HOOK) 安装进程内键盘钩子 (1)

    摘要:钩子能够监视系统或进程中的各种事件消息.截获发往目标窗体的消息并进行处理.这样,我们就能够在系统中安装自己定义的钩子,监视系统中特定事件的发生.完毕特定的功能,比方截获键盘.鼠标的输入.屏幕取词 ...

  6. C#鼠标键盘钩子

    using System;using System.Collections.Generic; using System.Reflection; using System.Runtime.Interop ...

  7. 什么是HOOK(钩子):消息拦截与处理

    对于Windows系统,它是建立在事件驱动机制上的,说白了就是整个系统都是通过消息传递实现的.hook(钩子)是一种特殊的消息处理机制,它可以监视系统或者进程中的各种事件消息,截获发往目标窗口的消息并 ...

  8. Hook(钩子技术)基本知识讲解,原理

    一.什么是HOOK(钩子)  API Windows消息传递机制,当在应用程序进行相关操作,例如点击鼠标.按下键盘,操作窗口等,操作系统能够感知这一事件,接着把此消息放到系统消息队列,然后到应用程序的 ...

  9. C# 键盘钩子

    p{ text-align:center; } blockquote > p > span{ text-align:center; font-size: 18px; color: #ff0 ...

随机推荐

  1. 001.CI4框架CodeIgniter的默认访问路径url

    1. 我们解压缩CI4的压缩包,找到app目录,点开Controllers目录,在Home.php文件中,写入我们的如下代码: 002.我们来访问我们的网站 http://127.0.0.1/CI4/ ...

  2. 07.Delphi接口的生命周期

    在Delphi的接口中,是不需要释放的,调用完之后,接口的生命周期就结束了,如下面的例子 unit mtReaper; interface type // 定义一个接口 IBase = interfa ...

  3. ubuntu18.04.2 Hadoop伪集群搭建

    准备工作: 若没有下载vim请下载vim 若出现 Could not get lock /var/lib/dpkg/lock 问题请参考: https://jingyan.baidu.com/arti ...

  4. POJ 1565:Skew Binary

    Skew Binary Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10676   Accepted: 6807 Desc ...

  5. GNS3 模拟icmp端口不可达

    R1 : conf t int f0/0 no shutdown ip add 192.168.1.1 255.255.255.0 no ip routing end R2 f0/0: conf t ...

  6. VLC搭建RTSP服务器的过程

    第一步,打开VLC 第二步:在媒体下拉菜单下!有一个子菜单“串流”如图所示: 点击“串流”子菜单 弹出一个窗口!如下图所示. 添加一个你要串流的本地文件,我刚才传给你的那个长一点的文件. 第三步,会出 ...

  7. liunx笔记

    Zolertia IPv6/6LoWPAN Ubidots client Son Han Border Router with Raspberry Pi for LLN with TelosBs Co ...

  8. 109-PHP类成员初始化值

    <?php class mao{ //定义猫类 public $age=0; //定义多个属性并初始化 public $weight=50; public $color='white'; } $ ...

  9. 第一个flink application

    导入maven依赖 需要注意的是,如果使用scala写程序,导入的依赖跟java是不一样的 Maven Dependencies You can add the following dependenc ...

  10. 哈希(hash)理解

    转载自https://www.cnblogs.com/mingaixin/p/4318837.html 一.什么是哈希?(一种更复杂的映射) Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就 ...