Imagesearch not working! Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Immortaxio135
Posts: 4
Joined: 20 Jan 2018, 01:40

Imagesearch not working!

20 Jan 2018, 01:55

Hello! I am new here.
I was trying to write a script to click generate button on this random number page until the number is 55.
So I pressed alt print screen to capture screen and crop image with paint then save it as .jpg.
I use window spy to find the position for checking image. The number from window spy that I used is from Window: xxx,xxx (default) under Mouse Position.
But nothing happens when the number is 55. Need help.
Thank you in advance.
Below is my code.

Code: Select all

^+H::
	loop {
		ImageSearch, Pos1, Pos2, 948, 346, 1121, 537, D:\number.jpg
		if (ErrorLevel = 0) {
			MsgBox Image is found!!!!
			Break
		}
		else if (ErrorLevel = 2) {
			MsgBox Could not conduct the search.
			Break
		}
		else {
			Click 990, 455 ; position of generate number button
			sleep 3000
		}
	}
return

Esc:: ExitApp
BoBo
Posts: 3642
Joined: 13 May 2014, 17:15

Re: Imagesearch not working!

20 Jan 2018, 03:53

Why not get this numbers using that: https://www.random.org/clients/http/ :?:
Immortaxio135
Posts: 4
Joined: 20 Jan 2018, 01:40

Re: Imagesearch not working!

20 Jan 2018, 05:11

Thank you for the reply, BoBo.

I am using this method because I just want to practice using ImageSearch so that I can use this function in the specific webpage which will available in the future.
When that webpage is available, I want to be able to monitoring number on the page and execute commands if that number changes from zero.
So I search for this number generator website to practice this ImageSearch command. But, as I stated, failed.
Any advice is appreciated.

Thank you in advance!
Sorry if I use English incorrectly.

Immortaxio135
foxhunter
Posts: 70
Joined: 04 Aug 2016, 04:27

Re: Imagesearch not working!  Topic is solved

20 Jan 2018, 05:53

Probably it wasnt found as you use jpg. Try other lossless formats like bmp or png or specify with *n the variations.
Immortaxio135
Posts: 4
Joined: 20 Jan 2018, 01:40

Re: Imagesearch not working!

20 Jan 2018, 07:54

Thank you so much for the reply, foxhunter.

After reading your post, I recaptured the screen and save the number file as .bmp and use *5
I run it but I got "Could not conduct the search." message which means that Errorlevel is 2.
I don't know why this happened.
The image file is 14*15 pixel with a bit depth of 4 and 238 bytes in size.

Any help is appreciated.
Below is my latest code.

Code: Select all

^+H::
	loop {
		ImageSearch, Pos1, Pos2, 877, 307, 1131, 550, *5 D:\number.bmp
		if (ErrorLevel = 0) {
			MsgBox Image is found!!!!
			Break
		}
		else if (ErrorLevel = 2) {
			MsgBox Could not conduct the search.
			Break
		}
		else {
			Click 962, 423
			sleep 3000
		}
	}
return
Thank you in advance.
Immortaxio135
foxhunter
Posts: 70
Joined: 04 Aug 2016, 04:27

Re: Imagesearch not working!

20 Jan 2018, 08:29

This should work normally, so please check if your file exists (this is one of the reasons why Imagesearch could not conduct the search). Maybe close the Image program, which could block this file. In addition sometimes could help, to active the program before doing an Imagesearch inside the program, e.g.:

Code: Select all

winactivate, ahk_exe firefox.exe
Immortaxio135
Posts: 4
Joined: 20 Jan 2018, 01:40

Re: Imagesearch not working!

20 Jan 2018, 11:57

Thank you very much foxhunter.
But I got the same error. No matter where the image is.
I have tried saving my image to D:\number.bmp, C:\number.bmp and script working dir then rewriting codes according to each place and reloading script. All failed.
So I guess it is related to type of image. I then saved the new image as png and it worked!
Below is the working code.
Thank you!

Code: Select all

^+H::
	winactivate, ahk_exe chrome.exe
	loop {
		ImageSearch, Pos1, Pos2, 877, 307, 1131, 550, number.png
		if (ErrorLevel = 0) {
			MsgBox Image is found!!!!
			Break
		}
		else if (ErrorLevel = 2) {
			MsgBox Could not conduct the search.
			Break
		}
		else {
			Click 962, 423
			sleep 1500
		}
	}
return

Return to “Ask For Help”

Who is online

Users browsing this forum: casperharkin, Gancito, Karrsen, Lorik, Paiter and 39 guests