实现的方法可能很笨,但是确实很好用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 自动化功能类
* Automation
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* 本类主要的目的是为了实现自动化的相关功能,实际上是通过一
* 种模拟用户操作的方式来实现的自动化库
* 程序由C#编写,但为Python等语言的调用做了兼容,目前本功能
* 库仅适用于Windows平台,最低兼容Windows 2000
* 理论上讲C#的程序没办法在Linux上直接运行,所以我把Linux中
* 几乎不可能用到的功能全部封装为C#库,而诸如内存、网络等功
* 能我通过C/C++进行封装
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
namespace Automation
{
// 核心操作器分配类
// 一般来说调用时,首先要声明一个AutomationOperation对象,然后根据该对象获取需要的操作器
// 再通过操作器进行操作
// 任何对类库的修改都决不允许修改操作器的调用方式,相当于对外封装了内部的细节
// 之后无论是要对程序进行扩展还是重写,只能增加和修改getOperation方法和Tools
// 即使一个功能不认为具有意义了,也不能轻易删除
public class AutomationOperation
{
// 单例模式
static Object MouseOperation = null;
static Object KeybdOperation = null;
// 用于测试是否能调取成功
public static void callTest()
{
System.Windows.Forms.MessageBox.Show("调用成功,测试通过!");
}
// 获取一个鼠标自动操作器
public Object getMouseOperation()
{
AutomationOperation.MouseOperation = new MouseTools();