锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 开源技术 / C#开源英语 / C#外挂技术系列-窗口控制例子翻译
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。

窗口控制例子界面介绍
This article presents a class, handling sending of input (mouse and keyboard) to any running Windows Control by its handle.
本文给出了一个类,通过句柄把(鼠标和键盘)的输入发送到任何运行Windows控件上。

背景


Some time ago, I was making a program which would win a penalty shootout soccer flash game for me. My task in the application was repeatedly to do these things: 前一段时间,我写个程序帮我赢个点球大战足球Flash游戏。程序的任务是反复做这些事情:

  • Grab flash window content抓取Flash窗口内容
  • Do some image processing and find out what to do进行图像分析,并找出该怎么做
  • Finally, take some action (send mouse input) 最后,采取行动(发送鼠标输入)

I found some great articles concerning taking of screenshot like this one. 对于截屏,我发现一些非常棒的文章,比如这一个
This library helped me with image processing a lot. 这个帮助我处理了很多图像分析的事务。
On the other hand, I spent a lot of time trying to find out how to send mouse input to flash window correctly... and when I got how to do it, I decided to make this library. 另一方面,我花了很多时间试图找出如何正确发送鼠标输入给Flash窗口... 时,我如何做到这一点,我决定完成这个库。

获取句柄


In order to use the TakeOver class, you need to obtain the handle (int number) of the window you want to control. It's possible to use spy++ tool from Visual Studio and convert HEX value to DEC using Windows calculator. The other possibility is to implement your own Window Picker (like in the demo project). Further details about this problem are out of scope for this article.为了使用TakeOver 类,你需要获得你想控制的窗口句柄(int number)。可用Visual Studio工具spy++,使用Windows计算器转换十六进制到十进制。另一种可能性是实现自己的窗口拾取器(如本文演示项目)。关于这个问题的进一步的细节超出了本文范围。

使用代码


The first thing you need to do to take control over the window is to create a TakeOver class instance. 要控制窗口,你需要做的第一件事就是创建一个TakeOver 类的实例。

                  Remo.TakeOver tO = new  Remo.TakeOver(targetWindowHandle); 

Sending of input messages to a window is quite self-explanatory. The class provides these methods for sendingmessages:
及时把输入消息发送给一个窗口比较明显易明。这个类提供了这些方法发送消息

                  public void SendLeftButtonDown(int x,int y);
public void SendLeftButtonUp(int x,int y);
public void SendLeftButtonDblClick(int x,int y);
public void SendRightButtonDown(int x,int y);
public void SendRightButtonUp(int x,int y);
public void SendRightButtonDblClick(int x,int y);
public void SendMouseMove(int x,int y);
public void SendKeyDown(int key);
public void SendKeyUp(int key);
public void SendChar(char c);
public void SendString(string s);

Sending input usually requires a target window to be focused to work properly, however it's not always so. The demo application can be tested here. Normally, you will have the application running in the background with controlled window focused, so there should be no problem with sending input messages. Since keyboard messages are not very reliable (I do not know how to encode lParam of SendMessage correctly, any hints?), it is recommended for keyboard input to use the SendKeys class once the window is focused via the SetFocus() method. Sendkeys is part of the standard System.Windows.Forms namespace. To focus target window TakeOver class provides a method:发送输入通常需要一个目标窗口有焦点能正常工作,但它并不总是如此。演示应用程序可以在这里测试。通常情况下,有应用程序会在后台运行,也会有带焦点的前台控制窗口,所以应该没有问题,发送 输入消息。因为键盘消息不是很可靠(我不知道如何正确编码 SendMessage的lParam,有提示不?),对键盘输入建议一旦窗口通过SetFocus()设置上焦点后才使用SendKeys 类。 Sendkeys是标准System.Windows.Forms的命名空间的一部分。为了设置焦点,TakeOver 类提供了一种方法:

 public void SetFocus();
友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内