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里怎么去 ...
随机推荐
- sourcetree的安装
参考博文: SourceTree安装教程和GitLab配置详解 关于Atlassian无法注册的问题 SourceTree跳过Atlassian账号,免登陆,跳过初始设置 sourcetree跳过注册 ...
- 013、MySQL取本月最后日期,取每个月的最后一天日期
#取本月最后一天 SELECT last_day( curdate( ) ); #取上个月最后一天 , INTERVAL MONTH ) ); , INTERVAL MONTH ) ); , INTE ...
- Hive 中的 order by, sort by, distribute by 与 cluster by
Order By order by 会对输入做全排序, 因此只有一个Reducer(多个Reducer无法保证全局有序), 然而只有一个Reducer, 会导致当输入规模较大时, 消耗较长的计算时间. ...
- 解析underscore中的throttle
什么是throttle(节流) Throttling enforces a maximum number of times a function can be called over time. 简单 ...
- java 如何爬取百度百科词条内容(java如何使用webmagic爬取百度词条)
这是老师所布置的作业 说一下我这里的爬去并非能把百度词条上的内容一字不漏的取下来(而是它分享链接的一个主要内容概括...)(他的主要内容我爬不到 也不想去研究大家有好办法可以call me) 例如 互 ...
- P1042 字符统计
P1042 字符统计 转跳点:
- android 动画基础绘——帧动画(三)
前言 这篇介绍帧动画. 什么是帧动画? 帧动画,非常好理解.就是轮播,比如我们看电视,其实就是一张一张播放过去的. 正文 <?xml version="1.0" encodi ...
- 167-PHP 文本分割函数str_split(二)
<?php $str='PHP is a very good programming language'; //定义一个字符串 $arr=explode(' ',$str,-3); //使用空格 ...
- 干货分享:反思Essay写作指南
在众多Essay写作类型中,有一种较为难写的一种类型——反思写作(Reflective Writing),提前熟悉这类写作风格的要求,并且养成反思性写作的习惯,非常有必要!本文小编就给大家说说什么是反 ...
- 换根dp
感觉这类问题很少?算了,还是拿出来水一下吧qwq... 首先来看一道例题:POJ3585 一句话题意:树上任意源点多汇点最大流 你看这不就是个最大流的板子题吗?我先建个图,然后跑最大流,然后,,,然后 ...