c#模拟鼠标移动的形式 [英] c# simulate mouse movement out of the form

查看:176
本文介绍了c#模拟鼠标移动的形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个问题困扰我一段时间。我想用c#模拟鼠标移动,我使用下面的代码:

there is a question bother me for a while. i want to simulate mouse movement by c#, and i use the codes below:

[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
       public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);





简单代码仅适用于应用程序。如何让它在表单之外工作?



thx。



the simple code only works with in the application. how to make it work out of the form?

thx.

推荐答案

另外,不要''使用 mouse_event 。即使使用P / Invoke很糟糕(请参阅解决方案1),有时您仍然需要使用它,以获得更强大的效果。但是过时的函数 mouse_event 已被另一个函数取代, SendInput

http://msdn.microsoft .com / zh-CN / library / windows / desktop / ms646310%28v = vs.85%29.aspx [ ^ ]。



这是如何在P / Invoke中使用它: http://www.pinvoke.net/default.aspx/ user32.sendinput [ ^ ]。



现在你有了所需的一切。



-SA
Also, don''t use mouse_event. Even though it''s bad to use P/Invoke (please see Solution 1), sometimes you still need to use it, for much more powerful effects. But the obsolete function mouse_event has been superseded with another function, SendInput:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

This is how to use it with P/Invoke: http://www.pinvoke.net/default.aspx/user32.sendinput[^].

Now you have all you need.

—SA


在没有极端需要的情况下不要使用P / Invoke;它会破坏你所有的平台兼容性。



使用Forms应用程序需要做的事情很容易在.NET FCL中完成。方法如下:

http:// msdn。 microsoft.com/en-us/library/system.windows.forms.cursor.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx [<一个href =http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspxtarget =_ blanktitle =New Window> ^ ]。



就这么简单。



-SA
Don''t use P/Invoke without extreme need; it will break all your platform compatibility.

What you need to do with a Forms application is quite easy working purely in .NET FCL. Here is how:
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx[^].

As simple as that.

—SA


这篇关于c#模拟鼠标移动的形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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