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里怎么去 ...
随机推荐
- CLion的使用
配置远程Linux编译器 实现目标:1.将项目中的源码和target和Linux服务器同步.2.代码在服务器端运行 配置ToolChains setting -> Build,Execution ...
- WAFの基本防护透明流模式v1.0
一.WAFの透明流模式 1)首先先配置WAF的网络,配置一个网桥接口,设置IP便于带内管理. 2)当然,如果需要不同网段之间都能够管 ...
- Python 日志模块详解
前言 我们知道查看日志是开发人员日常获取信息.排查异常.发现问题的最好途径,日志记录中通常会标记有异常产生的原因.发生时间.具体错误行数等信息,这极大的节省了我们的排查时间,无形中提高了编码效率.所以 ...
- HDU - 6201 transaction transaction transaction(spfa求最长路)
题意:有n个点,n-1条边的无向图,已知每个点书的售价,以及在边上行走的路费,问任选两个点作为起点和终点,能获得的最大利益是多少. 分析: 1.从某个结点出发,首先需要在该结点a花费price[a]买 ...
- Oracle 子程序、过程、函数
一.子程序 子程序是一个数据库对象,存在于数据库中,里面存放的是PL/SQL代码,可以完成一定的共能,能被程序和客户端工具直接调用.子程序类似于java中的方法,可以接接收参数,按照是否有返回值,子程 ...
- SharePreference的使用
SharePreference 一般用于保存偏好设置,比如说我们设置里的条目 sharepreference使用步骤 1.拿到sharepreference //拿到share preference ...
- 14.swoole学习笔记--异步读取文件
<?php //异步读取文件 swoole_async_readfile(__DIR__."/1.txt",function($filename,$content){ ech ...
- P3045 [USACO12FEB]牛券Cow Coupons
P3045 [USACO12FEB]牛券Cow Coupons 贪心题.先选中 \(c_i\) 最小的 \(k\) 头牛,如果这样就超过 \(m\) ,直接退出,输出答案.否则考虑把后面的牛依次加入, ...
- POJ 1426:Find The Multiple
Find The Multiple Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u Su ...
- Canvas绘制水波进度加载
效果: 用到图片下载: 自定义View: package com.czm.mysinkingview; import android.content.Context; import android.g ...