Pixelsearch on background inactive window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Pixelsearch on background inactive window

08 Nov 2022, 22:33

Yeah, check out the source for the class, every functions has documentation included, for PixelRegion it's PixelRegion(color,x1,y1,w,h,variance=0,byref returnX=0,byref returnY=0,scanDir:=0) so after variance you can specify an x and y return variable

Code: Select all

#include ShinsImageScanClass.ahk ;include the library
if WinExist("mywindow")
{
	scan := New ShinsImageScanClass("mywindow") 
	if (scan.PixelRegion(0x6D6EB6,243,99,280,403,3,foundX,foundY)) {     ;foundX, foundY contain the position
		ControlClick, x1113 y294, mywindow,,,, NA
	}
} else {
	Sleep 300
}
bobelyk
Posts: 64
Joined: 26 Jun 2021, 16:55

Re: Pixelsearch on background inactive window

10 Nov 2022, 18:03

bobelyk wrote:
08 Nov 2022, 12:21
Spawnova wrote:
29 Oct 2022, 10:44
When you compile an autohotkey script into an executable it automatically includes libraries that you have #included
You will only need the executable at that point, that's only for code though, other resources like images/audio will need to be present after
You script is being really usefull, i was wondering if the coords can be stored on a var to be randomized later
This is your script

Code: Select all

#include ShinsImageScanClass.ahk ;include the library
if WinExist("mywindow")
{
scan := New ShinsImageScanClass("mywindow") 
if (scan.PixelRegion(0x6D6EB6,243,99,280,403,3)) {     ;;;; I want to store the found x & y to a var
ControlClick, x1113 y294, mywindow,,,, NA
}
else {
	Sleep 300
}
Can something like this be added?

Code: Select all

Pixelsearch, Px, Py, 381, 15, 1684, 883, 0x55FDFD, 1, fast
if (ErrorLevel = 0) {
    Random, Rx , 0 , 3
    Random, Ry , 0 , 3
 Coordmode, Mouse, Client  
    Mousemove, Px+Rx, Py+Ry, 0
    Controlclick, Px+Rx, Py+Ry, 0 ;; ( Correct syntax? 
Sleep 100
}
Else {


}

woxaz
Posts: 13
Joined: 05 Apr 2021, 01:56

Re: Pixelsearch on background inactive window

07 Jan 2023, 02:51

Please help me to understand the ShinsImageScanClass.ahk class

search by pixel works perfectly, finds a pixel, shows coordinates, but does not work with search by image
I make a picture, I throw it in a folder with a script, and the script constantly finds a picture, even if this picture is not on the screen, what could be the problem


Code: Select all

!F5::
#include ../ShinsImageScanClass.ahk

scan := New ShinsImageScanClass() ;create an instance of the class
scan.Update() ;update buffer

if(scan.ImageRegion("test.png",571,0,230,355,0,x,y)){

	msgbox % "Image was found at " x ", " y
} else {
	msgbox % "Image not found"
}
Return
woxaz
Posts: 13
Joined: 05 Apr 2021, 01:56

Re: Pixelsearch on background inactive window

31 Jul 2023, 13:55

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetWorkingDir %A_ScriptDir%

#Include ShinsImageScanClass.ahk

hwnd := "QTranslate"
imagePath := "F:\AHK\TOP\PuloversMacroCreator-Portable\MacroCreatorPortable\x64\MacroCreator\Screenshots\Screen_20230730121900.png"
imageX := 0
imageY := 0

ScanObj := new ShinsImageScanClass(hwnd)

F6::
{
    Found := ScanObj.Image(imagePath, 0, imageX, imageY,1)
    if (Found = 1)
    {
        MsgBox, Image Found at (%imageX%, %imageY% , %hwnd%)
        ControlClick, x%imageX% y%imageY%, %hwnd%,,,, NA  ; Используйте ControlClick для клика на найденном изображении
    }
    else
    {
        MsgBox, Image Not Found!
    }
    return
}

The question in English would be: "How to perform a Control Click in this class? How should it be correctly written?"

Please note that the ControlClick command is not a method of the ShinsImageScanClass class. It is a built-in command in AutoHotkey that sends a mouse click to a given control. In your script, you are using ControlClick to click at the coordinates where the image was found. If you want to use ControlClick as a method of the ShinsImageScanClass class, you would need to add it to the class definition.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk, TAC109 and 353 guests