简体   繁体   English

如何监听其他进程的鼠标事件

[英]How can I listen to mouse events of other processes

是否可以在 C# 中侦听发送到其他进程中的其他窗口的与鼠标相关的窗口消息?

There is a open source project in codeplex for that codeplex 中有一个开源项目
Application and Global Mouse and Keyboard Hooks .Net Libary in C#应用程序和全局鼠标和键盘挂钩 C# 中的 .Net 库
If you want to do this yourself do some extra search on Windows Hooks如果您想自己执行此操作,请在Windows Hooks上进行一些额外的搜索
This article shows how 这篇文章展示了如何

You can take a look at the Codeplex Application and Global Mouse and Keyboard Hooks library你可以看看Codeplex Application 和 Global Mouse and Keyboard Hooks 库

This library attaches to windows global hooks, tracks keyboard and mouse clicks and movement and raises common .NET events with KeyEventArgs and MouseEventArgs, so you can easily retrieve any information you need:这个库附加到 windows 全局钩子,跟踪键盘和鼠标的点击和移动,并使用 KeyEventArgs 和 MouseEventArgs 引发常见的 .NET 事件,因此您可以轻松检索您需要的任何信息:
Mouse coordinates鼠标坐标
Mouse buttons clicked单击鼠标按钮
Mouse wheel scrolls鼠标滚轮滚动
Key presses and releases按键按下和释放
Special key states特殊键状态

From above links Documentation :从上面的链接文档

Before beginning it is important to know that hooking terms can and will be used interchangeably.在开始之前,重要的是要知道挂钩术语可以并且将可以互换使用。 Global hooks are also known as System, or System-Wide hooks, and will encompass the entire operating system.全局钩子也称为系统或系统范围的钩子,将涵盖整个操作系统。 Application hooks are often called Local, because as the name implies, will only correspond to the single application which placed the hook (or a specific thread).应用钩子通常被称为本地,因为顾名思义,它只会对应放置钩子的单个应用程序(或特定线程)。

There is no managed way to do this.没有管理的方法可以做到这一点。 However, with Windows Api this is possible:但是,使用 Windows Api,这是可能的:

This should help you.这应该对你有帮助。

C# - Capturing Windows Messages from a specific application C# - 从特定应用程序捕获 Windows 消息

It would be a good start to capture WM_MOUSEMOVE http://msdn.microsoft.com/en-us/library/windows/desktop/ms645616(v=vs.85).aspx捕获 WM_MOUSEMOVE 将是一个好的开始http://msdn.microsoft.com/en-us/library/windows/desktop/ms645616(v=vs.85).aspx

But there are other mouse related window messages, too.但是还有其他与鼠标相关的窗口消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM