wpf 使用 c# 实现鼠标自动化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13718082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mouse Automation with c#
提问by New Developer
Can we use Microsoft.VisualStudio.TestTools.UITesting.Mousefor automation purpose in a program (Is it possible to use it with our normal application cording. Not for the testing. )
我们可以Microsoft.VisualStudio.TestTools.UITesting.Mouse在程序中用于自动化目的吗(是否可以将它与我们正常的应用程序一起使用。不是用于测试。)
I want to automate some mouse movements in my program. Like we are doing in Microsoft UI automation. I am not going to create a test project.
我想在我的程序中自动化一些鼠标移动。就像我们在 Microsoft UI 自动化中所做的那样。我不打算创建一个测试项目。
If this is possible please advice me.
如果这是可能的,请给我建议。
Is mouse simulation is possible with UI automation?
UI自动化是否可以模拟鼠标?
EDIT
Since this is (Microsoft.VisualStudio.TestTools.UITesting.Mouse) used for coded UI testing I want to know is it possible to use in normal programming purpose. Because this Mouseclass has some of useful methods which I need.
编辑
因为这是 ( Microsoft.VisualStudio.TestTools.UITesting.Mouse) 用于编码的 UI 测试,我想知道它是否可以用于正常的编程目的。因为这个Mouse类有一些我需要的有用方法。
采纳答案by Mike Zboray
It may be technically possible to use it from an application. I believe all you need to do is make sure you call Playback.Initializebefore using the Mouseclass. However, I believe the license for VS will not allow you to redistribute the required dlls with your application.
从应用程序中使用它在技术上是可行的。我相信你需要做的就是确保Playback.Initialize在使用Mouse课程之前打电话。但是,我相信 VS 的许可证不允许您随应用程序重新分发所需的 dll。
UI Automation does not have facilities for low level input simulation.
UI 自动化没有用于低级输入模拟的工具。
I've use the TestApiproject with some success to automate mouse and keyboard input when UI Automation and the Coded UI api's could not be used. It is easy to accomplish moving and clicking the mouse with the the Mouseclass there:
当无法使用 UI 自动化和编码的 UI api 时,我已经成功地使用TestApi项目来自动化鼠标和键盘输入。使用那里的类很容易完成移动和单击鼠标Mouse:
using Microsoft.Test.Input;
using System.Drawing;
Mouse.MoveTo(new Point(100, 200));
Mouse.Click(MouseButton.Left);
回答by Kevin Coulombe
Setting the mouse location is as simple as this :
设置鼠标位置就像这样简单:
System.Windows.Forms.Cursor.Position = new Point(x, y);
You can also send click messages through the message loop using some pinvoke calls.
您还可以使用一些 pinvoke 调用通过消息循环发送单击消息。
I used this answersome time ago.
我前段时间用过这个答案。
EDIT
编辑
As I thought, you wouldn't be able to distribute your application with the Coded UI libraries without an additional license :
正如我所想的那样,如果没有额外的许可,您将无法使用编码的 UI 库分发您的应用程序:
How to run Coded UI Tests without Visual Studio 2010 Premium

