C#使用.xml文件模拟点击 [英] C# simulate clicks by using .xml file

查看:129
本文介绍了C#使用.xml文件模拟点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

社区.

我是这个论坛的新手.我已经使用Win32 API检验了几个示例,以模拟点击和光标移动.但是我有几个问题,希望有人可以回答.

1)使用win32 api和仅使用.Net Cursor.position有什么区别.

2)我需要构建一个从.xml文件读取的工具,并根据它读取的内容激活另一个程序中的某些内容.无论如何,是否需要单击正在运行的另一个程序中的特定项?例如,假设我从.xml文件开关1中读取了打开"信息,我可以以某种方式使光标转到开关1上吗?不使用x,y坐标?

我只需要知道是否可能,因为我不知道如何使用x,y坐标移动光标.

非常感谢您.

Hi Community.

I''m new in this forum. I have already checked out several examples using Win32 API in order to simulate clicks and cursor movements. However I have few questions, hopefully somebody can answer them.

1) what''s the difference between using win32 api and just using the .Net Cursor.position.

2) I need to build an tool that reads from an .xml file and depending on what it read it activates certain stuff in another program.Is there anyway to click on an specific item in the other program running? for example lets say I read from the .xml file switch 1 "on", can I somehow make the cursor go to switch one? without using x,y coordinates?

I just need to know if it is possible since I have no clue how to do move the cursor using the x,y coordinates.

thank you very much.

推荐答案

只有一种全面模拟鼠标和键盘输入的方法:P/调用原始Windows API SendInput,请参见 http://msdn.microsoft.com/en-us/library/ms646304%28v = vs.85%29.aspx [Cursor.Position实际上是System.Windows.Forms.System.Windows.Forms.Cursor.Position,它仅限于System.Windows.Forms以及读取和设置光标坐标的功能.如果您只需要它,那应该是您的首选方法.函数SendInput的作用还很多.自己看.

另一方面,使用P/Invoke完全破坏了您的应用程序平台兼容性.如果使用此功能,则代码仅在Windows上有效.如果编写纯.NET应用程序,将其限制为使用标准CLR库(以及许多非标准库,例如System.Windows.Forms),则无需重新编译即可在许多平台(例如Linux)上运行应用程序,Mac OS等. CLR在EMCA和ISO标准下进行了标准化,并在不同的平台上实现.一个最基本的产品就是Mono,请参见
http://en.wikipedia.org/wiki/Mono_%28software% 29 [ ^ ], http://www.mono-project.com/ [
There is only one method of comprehensive simulation of mouse and keyboard input: P/Invoked raw Windows API SendInput, see http://msdn.microsoft.com/en-us/library/ms646304%28v=vs.85%29.aspx[^].

Note that there are legacy functions keybd_event and mouse_event, but they were superseded by SendInput which is recommended to use.

The simulation is done on lower level and does not depend on and Windows, Forms, etc. The simulation is done as the events came from real keyboard and mouse.

That should answer your general questions and the question #2. Now, about your question #1, "the difference". First, please understand that no question in the format "what''s the difference between {0} and {1}?" can be logically correct. Try to answer such questions on the topics you''re well familiar with and you will feel it. The property Cursor.Position is actually System.Windows.Forms.System.Windows.Forms.Cursor.Position, it is limited to System.Windows.Forms and to the function of reading and setting the cursor coordinates. If you need just that, it should be your preferred method. The function SendInput does a lot more; look by yourself.

From the other hand, using P/Invoke totally breaks your application platform compatibility. If you use this function, your code will only work on Windows. If you write pure .NET application, limit it to the use of standard CLR libraries (and a lot of non-standard ones, such as System.Windows.Forms) you will be able to run your application without recompilation on many platforms, such as Linux, Mac OS and more. CLR is standardized under EMCA and ISO standard and is implemented on different platforms. One most essential product lik this is Mono, see http://en.wikipedia.org/wiki/Mono_%28software%29[^], http://www.mono-project.com/[^]. You can use all of that without much effort from your side if you refrain from using Windows-specific P/Invoke. You decide.

—SA


这篇关于C#使用.xml文件模拟点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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