windows键盘勾子的使用
来源:互联网 发布:网络歌手好听的歌2016 编辑:程序博客网 时间:2024/06/05 18:31
SetWindowsHookEx 原型如下
HHOOKSetWindowsHookEx(
int idHook, // 安装勾子的类型 键盘勾子=WH_KEYBOARD
HOOKPROC lpfn, // KeyboardProc回调函数的地址 最重要的参数就是这个了
HINSTANCE hMod, // 函有回调函数动态链接库的句柄 一般用LoadLibrary来获取
//也可以用GetModuleHandle获取 histance
DWORD dwThreadId // 要安装勾子的线程IDGetWindowThreadProcessId,
// (可以为0即全局勾子,将DLL注入到所有进程的线程)
);
回调函数格式
LRESULT CALLBACK KeyboardProc(
int code, // 这个值=HC_ACTION=0表示在wParam且lParam参数包含有关击键信息。
//假如这个值小于0(HC_ACTION)则回调函数返回值必需=CallNextHookEx返回值
//(也就是说必须调用一次CallNextHookEx,并把它的返回值给传给回调函数
WPARAM wParam, // 虚拟键码
LPARAM lParam // 击键信息资料 这个数的31位(bit)为0表示键按下,为1表示键释放
);
例子:
h:=FindWindow(nil,'Element Client');
GameTid:=GetWindowThreadProcessId(h);
SetWindowsHookEx(WH_KEYBOARD,@Keyproc,GetModuleHandle('???.dll'),GameTid);
Function keyproc(icode,wp,lp:integer):DWORD;stdcall; //键盘HOOK回调函数
begin
if (icode=HC_ACTION) then
begin
if (wp=VK_HOME)and ((1 shl 31)and lp=0) then
begin
// MessageBox(0,'显示外挂','显示外挂',0);
if form1=nil then Form1:=Tform1.Create(nil);
form1.Visible:=not form1.Visible;
end;
end;
keyProc:=CallNextHookEx(keyhhk,icode,wp,lp);
end;
Function installKeyProc():boolean;stdcall;
var
h:HWND;
GameTid:THandle;
begin
Result:=false;
h:=FindWindow(nil,'Element Client');
if h=0 then begin Messagebox(0,'未找到游戏','error',0);exit; end;//如果游戏未打开则退出
GameTid:=GetWindowThreadProcessId(h);
keyhhk:=SetWindowsHookEx(WH_KEYBOARD,@Keyproc,GetModuleHandle('dllGame.dll'),GameTid);
if keyhhk>0 then Result:=true;
end;
procedure DllEnterProc(reason:integer);
begin
case reason of
windows.DLL_PROCESS_ATTACH: begin end;
windows.DLL_PROCESS_DETACH: begin Form1.Free;form1:=nil; end;
end;
end;
exports //导出函数
add,
installKeyProc;
begin
//Messagebox(0,'Loading','error',0);
dllProc:=@DllEnterProc;
- windows键盘勾子的使用
- c# 键盘勾子
- AutoHotKey 的使用 —— 使用键盘调节 windows 声音
- Windows 的键盘快捷键
- Windows 的键盘快捷键
- emacs 在windows下使用的键盘布局
- windows判断用户是否在使用键盘鼠标的API
- 用FAAST把Kinect v2当作windows的键盘使用
- 键盘勾子匿名方法引起的异常
- DELPHI实现键盘勾子
- 深入分析C#键盘勾子(Hook)拦截器,屏蔽键盘活动的详解
- python在子线程中使用pyHook监控键盘无效,需要加pythoncom的初始化
- windows 键盘消息的机制
- windows下键盘的输入
- C#键盘勾子(Hook)拦截器,屏蔽键盘活动
- C#键盘勾子(Hook)拦截器,屏蔽键盘活动
- 键盘的使用
- dvorak键盘的使用
- 转载 Jquery Table 的基本操作
- Spring对Hibernate事务管理
- egret 适配问题 优化问题 新手引导
- 解决 java “错误:编码GBK 的不可映射字符”
- linux下安装ORACLE
- windows键盘勾子的使用
- RabbitMQ生产者模型
- 11期 8月期刊自荐
- MySQL 相关命令
- java中求区间之内的素数的个数,并输出素数
- LightOJ 1058Parallelogram Counting (数学+思维)
- Z-Wave Inclusion Flow
- hive--删除表中的数据truncate
- [LeetCode]--219. Contains Duplicate II