Negative image trigger ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Negative image trigger ?

Post by Fulminare » 29 Jul 2021, 22:42

How do I get AHK to trigger an action when a particular image is not found ?

Code: Select all

^d::
	imgFound := false
	while(imgFound = false)
	{
		imageSearch, x, y , 0, 0, 1000,600, LoL.png
		if(x <> "")
		{
			Send, {Enter}
			imgFound := true
		}
	}
return
[Mod edit: [code][/code] tags added.]


With the above code, If "LoL.png" is found, Enter key gets pressed.


I want the Enter Key to get pressed when LoL.png is NOT found

Can someone please guide me ?

Regards.
Ianizer
Posts: 79
Joined: 07 Mar 2021, 00:06

Re: Negative image trigger ?

Post by Ianizer » 29 Jul 2021, 23:01

You can check if ErrorLevel is set to anything except zero:

Code: Select all

^d::
imgFound := false
while (imgFound = false)
{
	ImageSearch, x, y , 0, 0, 1000,600, LoL.png
	if (ErrorLevel) ; saying if (variable) without any symbols like = or > means the same as: if (variable != 0 && variable != "") ;also != is the same as <>
	{
		Send, {Enter}
		imgFound := true
	}
}
return
Please read https://www.autohotkey.com/docs/commands/ImageSearch.htm#Error_Handling for an explanation. If it doesn't work, please let me know.
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Negative image trigger ?

Post by Fulminare » 29 Jul 2021, 23:35

@Ianizer

I tried using what you've sent me
it did not work

then I tried setting the error level to 1

- ErrorLevel = 1

it still did not work


what should I do ?
Rohwedder
Posts: 7568
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Negative image trigger ?

Post by Rohwedder » 30 Jul 2021, 01:39

Hallo,
perhaps:

Code: Select all

^d::
Loop
{
	ImageSearch, x, y , 0, 0, 1000,600, LoL.png
	if !imgFound := !ErrorLevel
		Send, {Enter}
}
Until, imgFound
return
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Negative image trigger ?

Post by Fulminare » 30 Jul 2021, 02:40

@Rohwedder

it does not seem to be working

What I am basically trying to do is :

I Programmed AHK to open OBS ( Open Broadcaster Software )

Before AHK clicks the " Start Virtual Camera" button, I want it to confirm if the video feed is on or not

When the video feed is on, my face gets displayed on the screen.

Now, I can take the screenshot of the display which has the image of my screen

But I am not sure how well AHK can support facial recognition

which is why I want to use the blank canvas's image

and trigger the mouse click at the "Start Virtual Camera" button when the blank canvas's image is not found

( if the blank canvas's image is not found, it means that the camera feed is on and I am visible )

I am attaching an image for clarity

ps: In my first question I have used "Send, {Enter}" just as an example
Attachments
OBS Image.png
OBS Image.png (51.27 KiB) Viewed 238 times
Rohwedder
Posts: 7568
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Negative image trigger ?

Post by Rohwedder » 30 Jul 2021, 03:47

But I am not sure how well AHK can support facial recognition
You're kidding!

Always proceed step by step. This snippet must work. Then and only then will the next step be taken.

Code: Select all

q::
imageSearch, x, y , 0, 0, 1000,600, LoL.png
MsgBox,% ErrorLevel
Return
https://www.autohotkey.com/docs/commands/ImageSearch.htm#Error_Handling
ErrorLevel is set to 0 if the image was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Negative image trigger ?

Post by Fulminare » 30 Jul 2021, 03:52

@Rohwedder

are you saying that I should first try the facial recognition thing ?
Rohwedder
Posts: 7568
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Negative image trigger ?

Post by Rohwedder » 30 Jul 2021, 04:20

Only if you have time to waste.
I assumed LoL.png would be the blank canvas's image.
Post Reply

Return to “Ask for Help (v1)”