在使用Win32Controller触发click没有生效,请问该如何处理 #319
Answered
by
kkkkninezzz
kkkkninezzz
asked this question in
Q&A
-
目标功能: 这里以MAA的桌面程序作为demo,识别 代码如下: import io.github.hanhuoer.maa.Maa;
import io.github.hanhuoer.maa.MaaOptions;
import io.github.hanhuoer.maa.callbak.MaaControllerCallback;
import io.github.hanhuoer.maa.consts.MaaWin32ControllerTypeEnum;
import io.github.hanhuoer.maa.core.Win32Controller;
import io.github.hanhuoer.maa.core.base.Instance;
import io.github.hanhuoer.maa.core.base.Resource;
import io.github.hanhuoer.maa.model.RecognitionDetail;
import io.github.hanhuoer.maa.model.Rect;
import io.github.hanhuoer.maa.model.TaskDetail;
import io.github.hanhuoer.maa.model.Win32Info;
import io.github.hanhuoer.maa.ptr.MaaCallbackTransparentArg;
import lombok.extern.slf4j.Slf4j;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
@Slf4j
public class MaaTest {
public static void main(String[] args) throws IOException {
MaaOptions options = new MaaOptions();
Maa maa = Maa.create(options);
List<Win32Info> win32Infos = Win32Controller.listInfo();
Optional<Win32Info> maaWindowOptional = win32Infos.stream()
.filter(info -> info.getWindowName().contains("MAA (Default)"))
.findFirst();
if (maaWindowOptional.isEmpty()) {
return;
}
Win32Info maaWindow = maaWindowOptional.get();
try (Win32Controller controller = new Win32Controller(maaWindow.getHwnd(), MaaWin32ControllerTypeEnum.TOUCH_SENDMESSAGE,
MaaWin32ControllerTypeEnum.KEY_SENDMESSAGE, MaaWin32ControllerTypeEnum.SCREENCAP_DXGI_FRAMEPOOL, new TestMaaControllerCallback(), null)) {
controller.connect();
Resource resource = new Resource();
resource.load("./resources/window_resources");
Instance instance = new Instance();
instance.bind(controller, resource);
if (!instance.inited()) {
System.out.println("Failed to init MAA.");
return;
}
RecognitionDetail findClearBtnTask = instance.runRecognition("findClearBtnTask");
System.out.println(findClearBtnTask);
// 尝试识别到位置后,触发click
// Rect hitBox = findClearBtnTask.getHitBox();
// int x = hitBox.getX() + hitBox.getW() / 2;
// int y = hitBox.getY() + hitBox.getY() / 2;
// controller.click(x, y);
}
}
public static class TestMaaControllerCallback implements MaaControllerCallback {
@Override
public void callback(String msg, String detailsJson, MaaCallbackTransparentArg callbackArg) {
log.info("msg: {}, detailsJson: {}, callbackArg: {}", msg, detailsJson, callbackArg);
}
}
} pipeline: {
"MyTask": {
"next": [
"findClearBtnTask"
]
},
"findClearBtnTask": {
"action": "Click",
"recognition": "TemplateMatch",
"template": "clear_btn.png",
"threshold": 0.8,
"roi": [129, 436, 209, 138]
}
} 识别结果: {
"all": [
{
"box": [
179,
486,
109,
38
],
"score": 0.995215
}
],
"best": {
"box": [
179,
486,
109,
38
],
"score": 0.995215
},
"filtered": [
{
"box": [
179,
486,
109,
38
],
"score": 0.995215
}
]
} |
Beta Was this translation helpful? Give feedback.
Answered by
kkkkninezzz
Aug 30, 2024
Replies: 2 comments 2 replies
-
send message 要看进程的,有些不能用。换另一个 seize 试试 |
Beta Was this translation helpful? Give feedback.
1 reply
-
另外 java binding 似乎有些 bug,没怎么测过( |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
调用win32 api应该是需要给管理员权限,我尝试管理员权限启动命令行后,再启动maaDebugger,通过sendMessage触发点击事件就是按照预期触发了