(一)辅助工具
Python脚本编辑器:推荐CodeAssistor(AutoPyTest独立工具Plugs目录下)
Windows控件分析:类Spy++的改动版(AutoPyTest独立工具Plugs目录下)
(二)Python脚本例子
import clr, sys
sys.path.append("C:\\Program Files\\IronPython 2.7\\Lib")
import os
clr.AddReference('IronPythonTest')
clr.AddReference('System.Windows.Forms')
from IronPythonTest import *
from System.Windows.Forms import *
from time import sleep
#s_hwnd = ApiMethod.FindWindow(None, "IronPythonTest (正在运行) - Microsoft Visual Studio");
#s_hwnd = ApiMethod.GetProcessMainFormHandle("devenv");
#ApiMethod.ShowWindow(s_hwnd, ApiCode.SW_MAXIMIZE);
#ApiMethod.SetForegroundWindow(s_hwnd);
#ApiMethod.SendStringXY(s_hwnd, "你好", 531, 66);
#from System.Windows.Forms.SendKeys
#SendKeys.SendWait("~");
os.popen("C: && C:\\Windows\\System32\\calc.exe","r")
sleep(3.0);
#_mainWnd = ApiMethod.FindWindow(None, "计算器");
mainWnd = ApiMethod.GetProcessMainFormHandle("calc");
sleep(1.0);
ApiMethod.ShowWindow(mainWnd, ApiCode.SW_SHOWDEFAULT);
ApiMethod.SetForegroundWindow(mainWnd);
sleep(1.0);
#ApiMethod.SetWindowCurrent(mainWnd);
#hwnd_button = ApiMethod.FindWindowEx(mainWnd, new IntPtr(0), null, "OK");
hwnd_button = ApiMethod.GetChildByID(mainWnd, 121);
ApiMethod.SendString(mainWnd,"1+2+4");
sleep(1.0);
ApiMethod.SendString(mainWnd, "*2");
sleep(1.0);
ApiMethod.SendMessage(hwnd_button,ApiCode.WM_CLICK , mainWnd, "0");
sleep(1.0);
SendKeys.SendWait("%{2}");
sleep(1.0);
SendKeys.SendWait("^{h}");
sleep(1.0);
flag=ApiMethod.ClickPosXY(mainWnd, 35, 38);
sleep(1.0);
flag=ApiMethod.ClickPosXY(mainWnd, 35, 38);
sleep(1.0);
SendKeys.SendWait("{F1}");
(三)界面和效果
AutoPyTest获取:
资源下载:http://download.csdn.net/detail/w565911788/4323928 (自解压绿色安装包)
需安装环境:dotNetFx40_Full_x86_x64.exe; IronPython-2.7.2.1.msi; (或以上)