Imagesearch fails if I use WinActivate, might could also use a hand with WinMove/SysGet

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jerf
Posts: 2
Joined: 20 Aug 2018, 01:37

Imagesearch fails if I use WinActivate, might could also use a hand with WinMove/SysGet

20 Aug 2018, 02:00

Trying to use WinActivate in the following code. If I leave it disabled then the ImageSearch works great. If I do WinActivate I get ErrorLevel1 (could not be found on screen).

Probably something to do with how I've set up ImageSearch coordinates in a direct manner for searching a region on my left (2nd of 3) monitor rather than trying to figure out prettier ways of doing it. But I'm still confused since WinActivate isn't doing anything to change my window positions so the search -should- work (in my head).

My monitor config, if it matters, is:

[#2 Left 1600x1200 landscape]
[#1 middle 2560x1600 landscape]
[#3 Right 1200x1600 portrait]
So the coordinates below are searching the 1600x1200 area on my left monitor.

[using AutoHotkey 1.1.26.01 on Win10_64 with BlueStacks 3N]

This works:

Code: Select all

#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%.
}
But if I uncomment either WinActivate line, the imagesearch returns code 1.

With the first WinActivate uncommented:
  • I first tried to sleep for a second, no joy.
  • I tried uncommenting WinWaitNotActive (manually clicking on another window after I was sure the WinActivate worked), no joy.
  • Then re-commented WinWaitNotActive and uncommented to WinActivate for notepad++.exe right after the first WinActivate, so see if I could bring the main window fore, then activate a different window, but no joy.
  • Additionally ... if I comment out the first WinActivate but leave the notepad++.exe activation in, the imagesearch also fails.
...

PS. I tried for awhile to get the ImageSearch and WinMove coordinates programatically with SysGet but got really frustrated. If someone bit on that part of the title, I'd appreciate the right method here.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Imagesearch fails if I use WinActivate, might could also use a hand with WinMove/SysGet

21 Aug 2018, 12:06

the imagesearch set of commands have their own CoordMode. have u tried CoordMode, Pixel, Screen already?
Jerf
Posts: 2
Joined: 20 Aug 2018, 01:37

Re: Imagesearch fails if I use WinActivate, might could also use a hand with WinMove/SysGet

23 Aug 2018, 18:26

Thank you. That alone doesn't quite fix it but definitely produces results different enough that I can find it on the main monitor. So I need to get better about defining my screen and coords. Much appreciated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 228 guests