如何找出挂钩密钥传递到的名称应用程序 [英] how to find out name application to which hooked key is passed

查看:53
本文介绍了如何找出挂钩密钥传递到的名称应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我设置了全局键盘和鼠标挂钩.我想要将钩子密钥传递给的exe应用程序的名称,以便它可以帮助我找到使用该密钥的应用程序.请告诉我,如何获取exe应用程序的名称(记事本,写字板等). /> 谢谢,

In my application,I set the global keyboard and mouse hook. I want to the name of exe application to which hooked key is passed so that it will help me for finding to which application that key is used.please tell me, How can get the exe application name(notepad,wordpad etc).
Thanks,

推荐答案

首先,您无需解释应用程序名称的含义.由于处理钩住消息的应用程序可以是任何东西(不仅是.NET程序集),因此没有这样的概念.太不同的应用程序可以携带相同的可执行文件名,Windows标头的相同文本,并且仍然不同,因此无论您做什么,都无法100%地确定标识.

您可以得到的是有关应用程序主窗口句柄的信息,以及由此产生的文本.首先,您需要使用P/Invoke获得一些本机Windows API方法.
您可以使用参数GW_OWNERGetParent调用Windows API GetWindow,以查找主要的应用程序窗口. (您总是使用GetWindowText来查找Windows标头的文本,但是正如我所说的,它不是一个可靠的唯一标​​识符.)

然后,您可以使用类System.Diagnostics.Process列出所有进程,并通过HWND标识显示相关窗口的进程.这样,您可以获得有关处理挂钩的过程的所有可用过程信息.

—SA
First of all, you don''t explain what do you mean by application name. As the application processing your hooked message can be anything (no only .NET assembly), there is no such concept. Too different application can carry the same executable file name, identical text of the windows header, and still be the different, so whatever you do, there in no 100% certain identification.

What you can get is the information on the application''s main window handle and hence its text. First of all, you need to obtain some native Windows API methods using P/Invoke.
You can call Windows API GetWindow with parameter GW_OWNER and GetParent to find out the main application windows. (You always use GetWindowText to find out the text of the windows header, but as I say, it is not a reliably unique identifier.)

Then you can list all processes using the class System.Diagnostics.Process and identify the process showing the windows in question by its HWND. This way you can obtain all available process information on the process processing your hook.

—SA


这篇关于如何找出挂钩密钥传递到的名称应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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