鼠标钩子用C# [英] Mouse hook with C#

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

问题描述

我试图效仿硬件点击鼠标,因为它似乎和PostMessage一些软件模块输入实例。我知道有SendInput,但我需要这是在后台与Windows兼容,以及这是不是一种选择。该解决方案似乎是一个低级别的鼠标钩子,但我周围中搜索,但没有找到不仅仅是记录器等任何东西,发生的不移动鼠标,点击等操作的,我想这无需编写一些排序C ++ / C包装作为一个假鼠标驱动程序使用。

I am trying to emulate "hardware" mouse clicks as it appears that some software blocks input from PostMessage for instance. I know there's SendInput, but that's not an option as I need this to be compatible in background windows as well. The solution seems to be a low-level mouse hook but I've searched around and couldn't find anything other than just the loggers, no manipulation of moving mouse, clicking etc. I'd like this to happen without having to write some sort of C++/C wrapper to use as a fake mouse driver.

http://support.microsoft.com/kb/318804 ,我发现这一点,但它似乎并没有被任何进一步的帮助。

http://support.microsoft.com/kb/318804, I found this but it doesn't seem to be of any further help.

任何帮助表示赞赏:)

推荐答案

不知道一些软件可能会,但肯定的是,UAC阻止你戳消息进入高架的程序的窗口。这就是所谓的UIPI,用户界面​​特权隔离。

Not sure what 'some software' might be, but sure, UAC stops you from poking messages into the windows of elevated programs. It is called UIPI, User Interface Privilege Isolation.

在一般情况下,伪造输入使用于PostMessage没有发挥丝毫作用。它是专为键盘输入一个问题,但鼠标的输入有困难了。还有就是要改变另一个进程的键盘状态没有什么好办法。当程序检查Shift键,Ctrl和Alt键的状态时,它处理输入的信息很重要。许多事情。

In general, faking input with PostMessage doesn't work well at all. It is especially a problem for keyboard input but mouse input has trouble too. There is no good way to alter the keyboard state for another process. That matters when the program checks the state of the Shift, Ctrl and Alt keys when it processes the input message. Many do.

唯一真正的解决办法是模拟输入与SendInput()。现在,你有一个重点解决的问题。

The only real solution is to emulate input with SendInput(). Now you got a focus problem to solve.

这篇关于鼠标钩子用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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