aardio自带了MSAA,UIA的相关库,MSAA库还好,UIA的库写起来太麻烦了,又懒得封装。于是找找现成的库直接玩玩,可惜flaui是mit协议。
import console;
import dotNet;
import mouse;
var Core = dotNet.load("FlaUI.Core","D:\Program Files (x86)\flaUI\Libs\FlaUI.Core.dll");
var UIA2 = dotNet.load("FlaUI.UIA2","D:\Program Files (x86)\flaUI\Libs\FlaUI.UIA2.dll");
var UIA3 = dotNet.load("FlaUI.UIA3","D:\Program Files (x86)\flaUI\Libs\FlaUI.UIA3.dll");
var Interop = dotNet.load("Interop.UIAutomationClient","D:\Program Files (x86)\flaUI\Libs\Interop.UIAutomationClient.dll");
Application = Core.import("FlaUI.Core.Application");
AutomationType = UIA3.new("FlaUI.UIA3.UIA3Automation");
TimeSpan = dotNet.import("System.TimeSpan","mscorlib.dll")
var app = Application.Attach("WeChat.exe");
console.log(app)
var window = app.GetMainWindow(AutomationType,TimeSpan.FromSeconds(2.0));
if(window){
console.log(window.Title)
var ele = window.FindFirstByXPath("/Pane[3]/Pane[2]/Pane[3]/Pane/Pane/Pane/Pane/Pane[2]/Pane[2]/Pane[2]/Pane/Pane[1]/Edit")
//window.FindAllByXPath("")
console.log(ele)
console.log(ele.BoundingRectangle)
window.SetForeground()
var rect = ele.BoundingRectangle;
x,y = rect.x + rect.Width/2 , rect.y + rect.Height/2
mouse.click(x,y,true)
}
console.pause()
demo2
import console;
import dotNet;
import mouse;
var assembly = dotNet.load("FlaUI",$"/res/FlaUI.dll");
assembly.import("FlaUI.UIA3");
root = FlaUI.UIA3.UIA3Automation().GetDesktop();
var tm = time.tick();
var ele = root.FindFirstByXPath("/Window[@Name='微信' and @ClassName='WeChatMainWndForPC']//Edit[@Name='输入']")
console.log(time.tick()-tm);
console.log(ele)
console.log(ele.BoundingRectangle)
ele.SetForeground()
sleep(3000)
var rect = ele.BoundingRectangle;
x,y = rect.x + rect.Width/2 , rect.y + rect.Height/2
mouse.click(x,y,true)
console.pause()
运行结果
dll直接从工具里面copy过来:
https://github.com/FlaUI/FlaUInspect/releases/tag/v1.3.0
网友评论