无句柄窗口也不是完全不能控制,
一种方法是使用 UI Automation 或 MSAA ,
举个例子读取 QQ 聊天消息( aardio 代码 )
import winex;
import winex.accObject;
import console;
for hwnd in winex.each( "TXGuiFoundation" ) {
var accObject = winex.accObject.fromWindow(hwnd)
if(accObject){
var accMessage = accObject.find(role="list")
if(accMessage){
for accChild in accMessage.each(){
console.log(accChild.roleText(),
accChild.name(),accChild.value())
}
}
}
}
console.pause(true);
还有一种方法是直接窗口截图文字识别, 用 aardio 写个例子:
import winex;
import string.ocrLite;
import string.ocrLite.defaultModels;
var ocr = string.ocrLite(,true);
var hwnd = winex.findExists("窗口标题");
if(!hwnd) return;
var ocrResult = ocr.detectClient(winform.hwnd);
if(ocrResult){
var x,y = ocrResult.findPoint("按钮文本",0.1);
if(x && y){
import mouse;
//无句柄窗口可以直接用 winex.mouse.click() 点击
mouse.moveToWindow(x,y,winform.hwnd);
mouse.click();
}
}