unit Unit1;
// download by http://www.codefans.net
interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
StdCtrls, ExtCtrls; type
TForm1 = class(TForm)
lbl1: TLabel;
lbl2: TLabel;
edt1: TEdit;
edt2: TEdit;
btn1: TButton;
btn2: TButton;
lst1: TListBox;
// ListBox1: TListBox;
// Button1: TButton;
// Button2: TButton;
// Edit1: TEdit;
// Edit2: TEdit;
// Label1: TLabel;
// Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure edt1Change(Sender: TObject);
procedure edt1KeyPress(Sender: TObject; var Key: Char);
procedure lst1DblClick(Sender: TObject);
private
function Keyhookresult(lP: integer; wP: integer): pchar;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hookkey: string;
hooktimes: word;
hHook: integer;
implementation
{$R *.DFM} function TForm1.Keyhookresult(lP: integer; wP: integer): pchar;
begin
result := '[Print Screen]';
{ VK_0 thru VK_9 are the same as ASCII '0' thru '9' ($30 - $39) }
{ VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' ($41 - $5A) }
case lp of
: result := '[Alt]'; //不能识别
: result := '`';
: Result := '';
: result := '';
: result := '';
: result := '';
: result := '';
: result := '';
: result := '';
: result := '';
: result := '';
: result := '';
: result := '-';
: result := '=';
: result := 'Q';
: result := 'W';
: result := 'E';
: result := 'R';
: result := 'T';
: result := 'Y';
: result := 'U';
: result := 'I';
: result := 'O';
: result := 'P';
: result := '[';
: result := ']';
: result := '\';
: result := 'A';
: result := 'S';
: result := 'D';
: result := 'F';
: result := 'G';
: result := 'H';
: result := 'J';
: result := 'K';
: result := 'L';
: result := ';';
: result := '''';
: result := 'Z';
: result := 'X';
: result := 'C';
: result := 'V';
: result := 'B';
: result := 'N';
: result := 'M';
: result := ',';
: result := '.';
: result := '/';
: result := '[Right-Shift]';
: result := '[Space]';
: result := '[Esc]';
: result := '[F1]';
: result := '[F2]';
: result := '[F3]';
: result := '[F4]';
: result := '[F5]';
: result := '[F6]';
: result := '[F7]';
: result := '[F8]';
: result := '[F9]';
: result := '[F10]';
: result := '[F11]';
: result := '[F12]';
: Result := '[Left-Shift]';
: result := '[CapsLock]';
: result := '[Backspace]';
: result := '[Tab]';
:
if wp > then
result := '[Right-Ctrl]'
else
result := '[Left-Ctrl]';
: result := '[Num /]';
: result := '[NumLock]';
: result := '[Print Screen]';
: result := '[Scroll Lock]';
: result := '[Pause]';
: result := '[Num0]';
: result := '[Num.]';
: result := '[Num1]';
: result := '[Num2]';
: result := '[Num3]';
: result := '[Num4]';
: result := '[Num5]';
: result := '[Num6]';
: result := '[Num7]';
: result := '[Num8]';
: result := '[Num9]';
: result := '[*5*]';
: result := '[Num *]';
: result := '[Num -]';
: result := '[Num +]';
: result := '[Insert]';
: result := '[Delete]';
: result := '[Home]';
: result := '[End]';
: result := '[PageUp]';
: result := '[PageDown]';
: result := '[UP]';
: result := '[DOWN]';
: result := '[LEFT]';
: result := '[RIGHT]';
: result := '[Enter]';
end;
end; //钩子回调过程
function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
var
s:string;
begin
result:=;//zl add
if (PEventMsg(lparam)^.message = WM_KEYDOWN) then
begin
//事件消息,键盘按下
s:=format('Down:%5d %5d ',[PEventMsg(lparam)^.paramL,PEventMsg(lparam)^.paramH])
+Form1.Keyhookresult(peventMsg(lparam)^.paramL, peventmsg(lparam)^.paramH);
Form1.lst1.Items.Add(s);
end
else if (PEventMsg(lparam)^.message = WM_KEYUP) then
begin
//键盘按键
s:=format(' Up:%5d %5d ',[PEventMsg(lparam)^.paramL,PEventMsg(lparam)^.paramH])
+Form1.Keyhookresult(PEventMsg(lparam)^.paramL,PEventMsg(lparam)^.paramH);
Form1.lst1.Items.Add(s);
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
hooktimes := ;
hHook := ;
end; procedure TForm1.btn1Click(Sender: TObject);
begin
inc(hooktimes);
if hooktimes = then
begin
hookkey := TimeToStr(now) + ' ';
hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, );
MessageBox(, '键盘监视启动', '信息', MB_ICONINFORMATION + MB_OK);
end;
end; procedure TForm1.btn2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook := ;
if hooktimes <> then
begin
MessageBox(, '键盘监视关闭', '信息', MB_ICONINFORMATION + MB_OK);
end;
hooktimes := ;
end; procedure TForm1.edt1Change(Sender: TObject);
var
i:DWORD;
begin
if length(edt1.text)<> then exit;
//映射虚拟键
i:=MapVirtualKey(ord(edt1.text[]), );
edt2.text:=format('%d %x',[i,i]);
end; procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
edt1.text:='';
end; procedure TForm1.lst1DblClick(Sender: TObject);
begin
lst1.clear;
end; end.

hook键盘钩子_非dll的更多相关文章

  1. hook键盘钩子 带dll

    library Key; uses SysUtils, Classes, HookKey_Unit in 'HookKey_Unit.pas'; {$R *.res} exports HookOn,H ...

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

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

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

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

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

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

  5. C#键盘钩子 鼠标钩子

    最新对C#模拟键盘按键,鼠标操作产生了兴趣.特从网上收集了一些常用的API用来调用键盘,鼠标操作. class Win32API { #region DLL导入 /// <summary> ...

  6. C#鼠标键盘钩子

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

  7. C# 键盘钩子

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

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

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

  9. WPF 利用键盘钩子来捕获键盘,做一些不为人知的事情...完整实例

    键盘钩子是一种可以监控键盘操作的指令. 看到这句话是不是觉得其实键盘钩子可以做很多事情. 场景 当你的程序需要一个全局的快捷键时,可以考虑使用键盘钩子,如大家常用qq的截图快捷键,那么在WPF里怎么去 ...

随机推荐

  1. node重点 模块

    node模块 1.全局模块(对象)(像js中的window document) 定义:何时何地都可以访问,不需要引用 1.process.env 环境变量 计算机属性 高级系统设置 高级 环境变量 作 ...

  2. Android明密文切换

    前言: 在我们的登录界面经常会遇到查看自己输入密码是否正确,就会用到明密文切换 正文: 我们先写出xml文件文件中的代码,不用过多解释 <EditText android:layout_widt ...

  3. P1010 一元多项式求导

    1010 一元多项式求导 (转跳点:

  4. Linux在实际中的应用

    各位童鞋们,你们是如何度过这周周末的呢?这周末的我在家学习学习再学习,然而学习到一半,公司领导突然给我打了个电话过来说有同事等会儿会去客户那部署无人值守安装系统服务,问我去不去学习下.我想我正在学Li ...

  5. wamp修改端口localhost

    一.修改Apache端口 1.在界面中选Apache,弹出隐藏菜单选项,打开配置文件httpd.conf: 2.找到 Listen 80: ServerName localhost:80; 3.将 8 ...

  6. Django——HttpResponse()

    HttpResponse(content, #返回给视图函数的内容 content_type=None,#返回给视图函数的类型 text/html文本.text/plain.css.js.xml.js ...

  7. 4. Linux 集群安装

    1. 配置yum yum clean all yum makecache yum install wget 2.安装JDK (1) 将jdk-7u60-linux-i586.rpm通过WinSCP上传 ...

  8. Apache服务器多站点配置

    Apache多站点设置,主要是关于httpd.conf配置文件的设置. 在httpd.conf配置文件中最后面的<VirtualHost>标签 #<VirtualHost *:80& ...

  9. (六--二)scrapy框架之持久化操作

    scrapy框架之持久化操作 基于终端指令的持久化存储 基于管道的持久化存储 1 基于终端指令的持久化存储 保证爬虫文件的parse方法中有可迭代类型对象(通常为列表or字典)的返回,该返回值可以通过 ...

  10. 51nod 1191:消灭兔子 贪心+优先队列

    1191 消灭兔子 题目来源: 2013腾讯马拉松赛第三场 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 有N只兔子,每只有一个血量B[i],需要 ...