C# - 挂钩到特定的应用程序 [英] C# - Hooking to a specific application

查看:55
本文介绍了C# - 挂钩到特定的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码成功挂接了桌面上所有打开的窗口和应用程序:

The following code hooks successfully of all open windows and applications on my desktop:

IntPtr hInstance = LoadLibrary("User32.dll");
callbackDelegate = new HOOKPROC(HookCallback);
hhook = SetWindowsHookEx(WH_KEYBOARD_LL, callbackDelegate, hInstance, 0);



但是,我会喜欢挂钩到特定的应用程序/窗口(比如记事本),可以这样做吗?


However, I would like to hook to a specific application/window (lets say Notepad), can it be done?

推荐答案

不,没有办法让消息针对特定的应用。您的钩子代码位于键盘驱动程序和带有输入焦点的控件之间。请注意,传递给钩子代码的数据中没有目标信息。你不知道它在哪里,也无法找到答案。
No, there is no way to get messages directed at a specific application. Your hook code sits between the keyboard driver and the control with the input focus. Notice that there is no destination information in the data that is passed to your hook code. You have no idea where it's going and no way to find out.


这篇关于C# - 挂钩到特定的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆