hook键盘钩子_非dll
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的更多相关文章
- hook键盘钩子 带dll
library Key; uses SysUtils, Classes, HookKey_Unit in 'HookKey_Unit.pas'; {$R *.res} exports HookOn,H ...
- 基于C#实现的HOOK键盘钩子实例代码
本文所述为基于C#实现的HOOK实例,该实例可用来屏蔽系统热键.程序主要实现了安装钩子.传递钩子.卸载钩子等功能.在传递钩子中:<param name="pHookHandle&quo ...
- 2.添加键盘钩子。向进程中注入dll
学习笔记 1.首先要建立mfc的动态链接库.在def文件中放入要导出的函数名. 2.添加函数如下 //安装钩子 //HHOOK SetWindowsHookEx( // int idHook,//钩子 ...
- 钩子编程(HOOK) 安装进程内键盘钩子 (1)
摘要:钩子能够监视系统或进程中的各种事件消息.截获发往目标窗体的消息并进行处理.这样,我们就能够在系统中安装自己定义的钩子,监视系统中特定事件的发生.完毕特定的功能,比方截获键盘.鼠标的输入.屏幕取词 ...
- C#键盘钩子 鼠标钩子
最新对C#模拟键盘按键,鼠标操作产生了兴趣.特从网上收集了一些常用的API用来调用键盘,鼠标操作. class Win32API { #region DLL导入 /// <summary> ...
- C#鼠标键盘钩子
using System;using System.Collections.Generic; using System.Reflection; using System.Runtime.Interop ...
- C# 键盘钩子
p{ text-align:center; } blockquote > p > span{ text-align:center; font-size: 18px; color: #ff0 ...
- 什么是HOOK(钩子):消息拦截与处理
对于Windows系统,它是建立在事件驱动机制上的,说白了就是整个系统都是通过消息传递实现的.hook(钩子)是一种特殊的消息处理机制,它可以监视系统或者进程中的各种事件消息,截获发往目标窗口的消息并 ...
- WPF 利用键盘钩子来捕获键盘,做一些不为人知的事情...完整实例
键盘钩子是一种可以监控键盘操作的指令. 看到这句话是不是觉得其实键盘钩子可以做很多事情. 场景 当你的程序需要一个全局的快捷键时,可以考虑使用键盘钩子,如大家常用qq的截图快捷键,那么在WPF里怎么去 ...
随机推荐
- Android Studio相关
1.下载安装 Android Studio 2.打开已有或是新建工程,gradle编译时候会报错(被墙),可以切换阿里的源 修改build.gradle 的配置: buildscript { repo ...
- HDU 5504:GT and sequence
GT and sequence Accepts: 95 Submissions: 1467 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- 51nod 1055:最长等差数列
1055 最长等差数列 基准时间限制:2 秒 空间限制:262144 KB 分值: 80 难度:5级算法题 收藏 取消关注 N个不同的正整数,找出由这些数组成的最长的等差数列. 例如:1 3 5 ...
- C#与unity中base64string和图片互转
C#: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- linux下安装redis,按照redis官网安装不成功需要提前安装c++环境(安装成功并可以测试)
这个安装是一种便捷的安装,没有几句,但是完全按照官网上的来没有安装成功,有前提条件的 打开linux root登录 然后在usr下面建文件夹redis,进入 在该文件加下,直接按照官网的指导进行安装即 ...
- 批量处理文件的Python程序
经常批量处理文件,这里有个python的模板,保存一下 这个例子是把目录里面所有子目录的mp3文件放慢0.85倍并保存到./processed/目录下面. #coding=utf-8 import s ...
- 3 —— node —— 文件追加内容
思想 : 先读取 , 再追加 const fs = require('fs') fs.readFile("./hello.txt","utf-8",(err,d ...
- 004、mysql使用SHOW语句找出服务器上当前存在什么数据库
SHOW DATABASES; 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢.
- jar包学习
jar: java的压缩包,主要用于存储类文件,或者配置文件等. 命令格式: jar -cf 包名.jar 包目录 解压缩: jar -xvf 包名.jar 将jar包目录列表重定向到一个文件中: j ...
- 简单javascript学习总结
2019-10-19 //文章汇总于绿叶学习网 console.log() //控制台输出 目录 数据类型:.... 2 函数:.... 3 ...