Perform an Action if a Specific Image Is Within a Defined Area

Hey,

I like the found-image-action within KM but is it possible to put it the other way round and define an on screen area and tell KM to perform an action if a specific image is within this area.

A little more detailed. Within Media Composer I would like to ‚solo‘ a track with a hotkey. I have a fixed workspace so by default I can use the mouse-action but depending on whether there’s a master clip, a sequence or nothing in the source monitor the position of the ’s’-button changes horizontally (See examples).

My goal is to set up an if/else-action and tell KM if the image is found within that area perform a click otherwise move the mouse to the other possible positions.

Best,

Simon



The if/else action has the ability to search an area of the screen for an image and act accordingly. Something like the action below should work for you.

-Chris

Action Screenshot (click to expand/collapse)

If Then Else.kmactions (2.3 KB)

1 Like

Thanks a lot Chris!
I'm almost successful with this macro.
When there is a master clip in the source monitor (A) or no source (B) in the source monitor it works fine.
Only the third case when there is a sequence clip in the source monitor (C) KM clicks at the first case position (A).
Any ideas?
Solo A1.kmmacros (14.8 KB)

Gotcha, you basically need to click at one of three found images. Ok there’s multiple ways of doing that. You could use a separate If/else action for each image, and if “image a” (or “image b”, “image c” etc.) is found, then click relative to it, else do nothing. I have used this method quite a bit in the past to look for multiple images and it works quite well.

However, there is another way I have seen mentioned on the forum that should also work. Below is a demo macro (you need to fill in the images, and adjust the numbers in the click mouse action) that might work as well, and is a little more concise. DISCLAIMER: I have never tried this method because I got away from using found image actions awhile ago, but I’ve always wanted to try it haha.

Click relative to one of three found images.kmmacros (7.6 KB)

Macro screenshot (click to expand/collapse)

2 Likes

Hey Chris,
Thanks for the effort. Very interesting. I'm learning something.
Sorry for the dumb question but in your macro what does KM actually do? I define three different images to be found but on which image does KM eventually click?
I don't get it.
In terms of my case I guess you misunderstood me.
'you basically need to click at one of three found images' is not really my situation.
It's rather that KM should look for a particular image in three possible positions.
I thought I'm on a good way with the If/else-actions in my macro but somehow it doesnt work (see my first reply for details)
Again thanks and have a nice evening,
Simon

Hey Simon,

In my version, it looks for three different images and clicks on whichever one it finds. That’s what I thought you needed.

However, if all you need is to click on a single image that doesn’t change, but whose location does change, then that is even easier. Just setup a click on found image and set it to in area or in front window etc. This way KM will look for that image in whatever location(s) you specify.

Let me know if that doesn’t make sense and I can give you an example this evening or weekend!

-Chris

Hey Chris,

Thanks for your help and wisdom!

So I came up with this macro and I'm almost there. It works for the Case '2' and '3' right but not for Case '1' (In this case it performs the '2'-condition, meaning mouse moves to the Case-'2'-scenario).

Any ideas?

Cheers,
Simon


Solo A1.kmmacros (13.5 KB)

Hey,

Does anyone have an idea?

It bugs me not to understand where the mistake is...

Cheers,
Simon

It's very difficult to debug a macro that relies on found images when you don't have the program, don't have the same size screen, have no coordinate references on the images, etc.

But I think your use of Global variables is masking the real problem. Globals persist across runs -- if Solo Location is set to 2 in the first execution and then you run the macro when there's no source clip in the source monitor but the image detection fails, Solo Location will still be set to 2 and the wrong thing will happen.

Also, you only need one "Switch/Case" action -- you test the condition then do this or this or this depending on the result. And it's good to have an "otherwise" to handle all other cases:

image

I've used the same Global variable as you so you can easily see what's happening but, again, you should change to using a Local (unless you need the value to persist, for example so you can use it in another macro). If it is a Local it won't have a value if all three image detects fail and you'll get an obvious indication via the "Switch/Case" action's "otherwise" dialog.

2 Likes

Hey Simon,

Sorry for not getting back to you sooner; been a busy week.

@Nige_S posted some good advice. Please let us know what you experience when implementing his suggestion and we’ll go from there.

Have a great weekend!

-Chris

1 Like

Thanks Nige I check that out first thing tomorrow.

Hey Chris,
Sorry for my impatience and thanks for getting back to me. I will let you when I was sucessful.
Cheers,
Simon

1 Like

Hey Nige and Chris,
Thanks so much! It works (almost) perfectly!
From time to time the mouse click is not always in the right area (especially right after the cases change)
but definitely a situation I can work with.
Kind regards,
Simon

1 Like

Hey Simon, glad to hear! Yes, that is one of the drawbacks to found image actions, they’re about 99% reliable, but there’s always that 1% haha.

Have a great day!