Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

c# - C#鼠标钩(Mouse hook with C#)

I am trying to emulate "hardware" mouse clicks as it appears that some software blocks input from PostMessage for instance.

(我试图模拟“硬件”鼠标单击,因为似乎某些软件例如阻止了来自PostMessage的输入。)

I know there's SendInput, but that's not an option as I need this to be compatible in background windows as well.

(我知道这里有SendInput,但这不是一个选择,因为我也需要在后台窗口兼容。)

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.

(解决方案似乎是一个低级的鼠标钩,但我进行了搜索,除了记录器之外,找不到其他东西,没有对移动鼠标,单击等的任何操作。一种用作伪造的鼠标驱动程序的C ++ / C包装器。)

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

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

Any help appreciated :)

(任何帮助表示赞赏:))

  ask by miceiken translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not sure what 'some software' might be, but sure, UAC stops you from poking messages into the windows of elevated programs.

(不知道可能是什么“某些软件”,但可以肯定的是,UAC阻止您将消息发送到高级程序的窗口中。)

It is called UIPI, User Interface Privilege Isolation.

(它被称为UIPI,用户界面特权隔离。)

In general, faking input with PostMessage doesn't work well at all.

(通常,用PostMessage伪造输入根本无法正常工作。)

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.

(当程序在处理输入消息时检查Shift,Ctrl和Alt键的状态时,这一点很重要。)

Many do.

(很多。)

The only real solution is to emulate input with SendInput().

(唯一真正的解决方案是使用SendInput()模拟输入。)

Now you got a focus problem to solve.

(现在您有一个重点问题要解决。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...