Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

AHK ImageSearch for AutoIT


Rekomendowane odpowiedzi

Opublikowano

Z uwagi na to, że używana w Autoit funkcja ImageSearch nie działa u wielu osób (najpierw sprawdź to rozwiązanie: http://www.mpcforum.pl/topic/1455511-ca%C5%82y-czas-t%C5%82uk%C5%82o-ale-to-tak-t%C5%82uk%C5%82o-click-to-migacz/#entry12338349 ) zamieszczam tutaj interfejs pozwalający korzystać z bliźniaczej funkcji ahk (która jest raczej niezawodna). Oczywiście zdaję sobie sprawę, że nie jest to rozwiązanie optymalne (najlepsza byłaby natywna funkcja), ale była potrzeba, więc coś takiego zrobiłem - może się komuś przyda.
 
Z interfejsu korzystamy wywołując plik ImageSearch.exe z odpowiednimi parametrami:

RunWait('ImageSeach.exe ścieżka tolerancja x1 y1 x2 y2 tryb') 

ścieżka - ścieżka do obrazka z szukanym wzrorcem względem pliku ImageSearch.exe, np. example.bmp (zalecam używanie tylko plików .bmp i .png) (wymagane!)
tolerancja - tolerancja odcieni między wzorcem a szukanym obrazem - od 0 do 255 (opcjonalne, domyślnie 0)
x1 - współrzędna x lewego górnego rogu przeszukiwanego obszaru (opcjonalne, domyślnie 0)
y1 - współrzędna y lewego górnego rogu przeszukiwanego obszaru (opcjonalne, domyślnie 0)
x2 - współrzędna x prawego dolnego rogu przeszukiwanego obszaru (opcjonalne, domyślnie szerokość ekranu)
y2 - współrzędna y prawego dolnego rogu przeszukiwanego obszaru (opcjonalne, domyślnie wysokość ekranu)
tryb - rodzaj zwracanych współrzędnych: 0 - względem okna, 1 - względem ekranu, 2 - względem obszaru roboczego (opcjonalne, domyślnie 1)

Współrzędne znalezionego obrazka są zapisywane w schowku (rozdzielone przecinkiem) - należy je pobrać za pomoca funkcji ClipGet(). W przypadku błędu funkcja zwróci zamiast współrzędnych "error", w przypadku nie znalezienia obrazka zwróci "miss".
 
Przykład użycia:

 

 


HotKeySet("p", "checkForImage")

Func checkForImage()
    RunWait('ImageSeach.exe examle.bmp 50')
    Local $result = ClipGet()   
    If $result = "error" Then
        MsgBox(0, "", "Błąd")
    ElseIf $result = "miss" Then
        MsgBox(0, "", "Nic nie znaleziono.")
    Else
        Local $coords = StringSplit($result, ",")
        MouseMove($coords[1], $coords[2], 1)
    EndIf
EndFunc

while 1
sleep(100)
WEnd 

 



Kod źródłowy ImageSearch.exe dla dociekliwych (ahk):

 

 


#NoEnv
#NoTrayIcon
SetWorkingDir %A_ScriptDir%

path = %1%
tolerance = %2%
x1 = %3%
y1 = %4%
x2 = %5%
y2 = %6%
mode = %7%

if(path = "" OR path = 0)
{
    clipboard := "error"
    ExitApp
}
if(tolerance = "")
    tolerance := 0
if(x1 = "")
    x1 := 0
if(y1 = "")
    y1 := 0
if(x2 = "" OR x2 = 0)
    x2 := A_ScreenWidth
if(y2 = "" OR y2 = 0)
    y2 := A_ScreenHeight
if(mode = "")
    mode := 1

if(mode = 0)
    CoordMode, Pixel, Window
else if(mode = 1)
    CoordMode, Pixel, Screen
else if(mode = 2)
    CoordMode, Pixel, Client

ImageSearch, FoundX, FoundY, %x1%, %y1%, %x2%, %y2%, *%tolerance% %path%
if ErrorLevel = 2
    clipboard := "error"
else if ErrorLevel = 1
    clipboard := "miss"
else
    clipboard := FoundX "," FoundY
ExitApp 

 



 
 
Skan: https://www.virustotal.com/pl/file/a53b2daab9536e4cb5dcc69bcb698f91e98ef5d4a5d783867e788e4645b3ea42/analysis/1439952168/

(3 fałszywe alarmy na 56 - to normalka w przypadku execów - wszystkie popularne antywirusy uznaja go za bezpieczny)

Chcesz precyzyjnej i zrozumiałej odpowiedzi? - Zadaj precyzyjne i zrozumiałe pytanie. Nie przyjmuję zleceń.
Nie odpowiadam na priv na pytania, które można zadać na forum. Chcesz mojej pomocy - oznacz mnie w poście =>  @"Hans Kloss PL" 

  • 2 miesiące temu...
Opublikowano

Przerobilem UDF ImageSearch tak aby dzialal z tym co stworzyl @@Hans Kloss PL
 
ImageSearchMPC.au3

 

#include-once

#Include <GDIPlus.au3>

; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Image Search
;                 Require that the AHK ImageSeach.exe
;
; ------------------------------------------------------------------------------

;===============================================================================
;
; Description:      Find the position of an image on the desktop
; Syntax:           _ImageSearchArea, _ImageSearch
; Parameter(s):
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
;                   @error:
;                   		2 - Error
;                   		3 - Image not found
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom, ByRef $x, ByRef $y, $tolerance)
	$What2Search = "ImageSeach.exe " & $findImage & " " & $tolerance & " " & $x1 & " " & $y1 & " " & $right & " " & $bottom
	RunWait($What2Search)
	$result = ClipGet()
	If $result = "error" Then
		SetError(2)
		Return 0
	ElseIf $result = "miss" Then
		SetError(3)
		Return 0
	Else
		$coords = StringSplit($result, ",")
		$x = $coords[1]
		$y = $coords[2]
		If $resultPosition = 1 Then
			_GDIPlus_Startup()
			$hImage = _GDIPlus_ImageLoadFromFile($findImage)
			$x= $x + (_GDIPlus_ImageGetWidth($hImage)/2)
			$y= $y + (_GDIPlus_ImageGetHeight($hImage)/2)
			_GDIPlus_ImageDispose($hImage)
			_GDIPlus_ShutDown()
		EndIf
		Return 1
	EndIf
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for an image to appear
;
; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):
;					$waitSecs  - seconds to try and find the image
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition, ByRef $x, ByRef $y,$tolerance)
	$waitSecs = $waitSecs * 1000
	$startTime=TimerInit()
	While TimerDiff($startTime) < $waitSecs
		sleep(100)
		$result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance)
		if $result > 0 Then
			return 1
		EndIf
	WEnd
	return 0
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for any of a set of
;                   images to appear
;
; Syntax:           _WaitForImagesSearch
; Parameter(s):
;					$waitSecs  - seconds to try and find the image
;                   $findImage - the ARRAY of images to locate on the desktop
;                              - ARRAY[0] is set to the number of images to loop through
;								 ARRAY[1] is the first image
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):  On Success - Returns the index of the successful find
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition, ByRef $x, ByRef $y,$tolerance)
	$waitSecs = $waitSecs * 1000
	$startTime=TimerInit()
	While TimerDiff($startTime) < $waitSecs
		for $i = 1 to $findImage[0]
		    sleep(100)
		    $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
		    if $result > 0 Then
			    return $i
		    EndIf
		Next
	WEnd
	return 0
EndFunc

 


Download:

http://www74.zippyshare.com/v/uMEXbfgr/file.html 

 

 

  • 1 miesiąc temu...
Opublikowano

Mamy się domyślić co nie działa ? Może w ogóle nie działa bo robisz źle. 

Mózg to nie mydło; nie ubędzie Ci go, gdy go użyjesz.

Opublikowano

@†Silver•King†

Masz wklejony kod źródłowy, wystarczy skopiować, nie musisz pobierać zipa.

Chcesz precyzyjnej i zrozumiałej odpowiedzi? - Zadaj precyzyjne i zrozumiałe pytanie. Nie przyjmuję zleceń.
Nie odpowiadam na priv na pytania, które można zadać na forum. Chcesz mojej pomocy - oznacz mnie w poście =>  @"Hans Kloss PL" 

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...