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. wdcp升级php5.8到php7.1.12

    php7升级脚本 update_php7.sh #!/bin/bash # PHP update scripts ];then Ver= else Ver=$ fi Debugfile= echo & ...

  2. Spark Storage 模块

    http://jerryshao.me/architecture/2013/10/08/spark-storage-module-analysis/ 大神写的太好了,我就不重复造轮子了. Spark ...

  3. PL/SQL 找到某列都为空的列名

    DECLARE CURSOR temp IS SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME=Upper('xxx'); v_num ...

  4. 关于 CDN 负载均衡 网页请求过程等

    链接 1 [转]浅谈一个网页打开的全过程(涉及DNS.CDN.Nginx负载均衡等)  https://www.cnblogs.com/xuan52rock/p/6845637.html 2 闲话 C ...

  5. Java 类的属性

    章节 Java 基础 Java 简介 Java 环境搭建 Java 基本语法 Java 注释 Java 变量 Java 数据类型 Java 字符串 Java 类型转换 Java 运算符 Java 字符 ...

  6. redis简单的实现(java)

    1.首先新建一个maven项目,在pom.xml中添加依赖 <dependency> <groupId>redis.clients</groupId> <ar ...

  7. TBLASTN

    TBLASTN search translated nucleotide databases using a protein query

  8. C语言备忘录——static

    对于这个关键字我一直没有弄清楚,今天特地去花了一定的时间去理解这个关键字.在函数或变量声明时,在数据类型前加上 static 后会有以下几个效果 一.用于函数定义时: 1.函数的链接属性会被修改,从e ...

  9. 每天一点点之 uni-app 框架开发 - 页面滚动到指定位置

    项目需求:在页面中,不管位于何处,点击评论按钮页面滚动到对应到位置 实现思路如下: uni.createSelectorQuery().select(".comment").bou ...

  10. 068-PHP定义并输出数组

    <?php $arr=array(98,'hello',67,'A',85,NULL); //定义一个数组 echo "输出第一个元素:{$arr[0]}"; //输出数组的 ...