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. Java中JSON字符串与java对象的互换实例详解(转)

    http://www.jb51.net/article/90914.htm 在开发过程中,经常需要和别的系统交换数据,数据交换的格式有XML.JSON等,JSON作为一个轻量级的数据格式比xml效率要 ...

  2. 吴裕雄--天生自然java开发常用类库学习笔记:Map接口使用的注意事项

    import java.util.HashMap ; import java.util.Map ; import java.util.Set ; import java.util.Iterator ; ...

  3. F. Fairness 分硬币最大差值最小

    F. Fairness time limit per test 2.0 s memory limit per test 64 MB input standard input output standa ...

  4. Docker-harbor-V1.3.0 ”私有仓库“搭建 Easy

    准备: centos     7.0 Docker version 1.12.6    docker-compose version 1.19.0   1: updata-yum:   更新yum 源 ...

  5. 【转帖】影响超 10 亿设备,博通和 Cypress 芯片曝惊天漏洞,苹果、华为、三星等中招

    影响超 10 亿设备,博通和 Cypress 芯片曝惊天漏洞,苹果.华为.三星等中招   https://www.infoq.cn/article/lpNEQGrxZL22gHDPBE2z   26 ...

  6. LeetCode题解汇总(包括剑指Offer和程序员面试金典,持续更新)

    LeetCode题解汇总(持续更新,并将逐步迁移到本博客列表中) LeetCode题解分类汇总(包括剑指Offer和程序员面试金典) 剑指Offer 序号 题目 难度 03 数组中重复的数字 简单 0 ...

  7. POJ3616:Milking Time

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5682   Accepted: 2372 Desc ...

  8. js ajax跨域调用

    正常使用ajax调用java.com $.ajax({ type: 'get', url: 'http://www.java.com/custinfo?id=888', dataType: 'json ...

  9. 四十、SAP中CASE语句用法

    一.上代码 二.选择内容 三.输出 四.我们选择一个其他的值 五.查看输出

  10. 移动MAS短信平台发送短信

    MAS短信平台发送短信分为两种方式 参考文档下载 一.sdk调用 using mas.ecloud.sdkclient; using System; namespace 短信发送 { class Pr ...