尝试在以下代码中使用WinActivate。如果我将其禁用,则ImageSearch效果很好。如果我执行WinActivate,则会收到ErrorLevel1(在屏幕上找不到)。
可能与我如何直接设置ImageSearch坐标以搜索左侧(第2个,第3个)监视器的区域有关,而不是试图找出更漂亮的方法。但是我仍然感到困惑,因为WinActivate并没有做任何改变窗口位置的事情,因此搜索(应该在我头上)应该可以进行。
我的监视器配置(如果重要)是:
[#2左1600x1200风景]
[#1 2560x1600风景中间]
[#3右1200x1600肖像]
所以下面的坐标正在我的左显示器上搜索1600x1200区域。
[在带有BlueStacks 3N的Win10_64上使用AutoHotkey 1.1.26.01]
此有效:
#NoEnv
SetWorkingDir %A_ScriptDir%
;CoordMode, Mouse, Window
;CoordMode, Mouse, Screen
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
DetectHiddenWindows Off
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
program = ahk_exe BlueStacks.exe
search_images = AutoHotkey_images\search
;WinActivate, %program%
;sleep 1000
;WinWaitNotActive, %program%
;WinActivate, %A_ScriptName%
WinMove, %program%,,IS_y2*-1,238,1600,1200 ; total hack to place the window as if it were maximized
; mostly just ignore, relative to my monitor position
/*
* Adjust the next 4 variables until you match on your screen.
... Example if using only a single 1920x1080 screen OR you're ok with this going on your PRIMARY monitor:
(With BlueStacks at 1600 width and top-left corner at top-left of your monitor):
IS_x1 = 0
IS_y1 = 0
IS_x2 = 1600
IS_y2 = 1080
*/
IS_x1 = -4160 ; locations on current virtual desktop, working
IS_y1 = 0
IS_x2 = -2560
IS_y2 = 1600
ImageSearch, FoundX, FoundY, IS_x1, IS_y1, IS_x2, IS_y2, %search_images%\map_select_a_location.png
if (ErrorLevel = 2) {
MsgBox Could not conduct the search.
} else if (ErrorLevel = 1) {
MsgBox Icon could not be found on the screen.
} else {
MsgBox The icon was found at %FoundX%x%FoundY%.
}
但是,如果我取消注释任一WinActivate行,则imagesearch返回代码1。
未对第一个WinActivate进行注释:
...
PS。我试了一会儿用SysGet以编程方式获取ImageSearch和WinMove坐标,但感到非常沮丧。如果读者在那里得到帮助,我将感谢使用正确的方法。