Questions about image found

Hello, I've download this software few hours ago and im practicing in a 2d game for fun.
what I need?
there's a bar with my health points, I want a macro to press "X" hotkey if / while the macro found the image from 50%, 45%, 40%, 35%, 30%, 25%, 20%, 15%, 10%, 5% of my health points bar.
I have photos from the bar for every 5%

ive tried to do like this:
when application "game" activates


but idk why it isn't working, when I do alt tab to the game it just random press F3 sometimes and them stop, can someone help me, what im doing wrong? Is The logic is totally wrong?

Hello,
50%
This bar is half (50%) full
What I want to do is when the macro recognise that while this bar is 50% or less it need to press a hotkey (F3)
Ive noticed that when I select a display area size it marks with green and give a percentage, I would like to know if KM can calculate this percentage with the area that I gave and use it for my macro. Am im going to the right way?

Ive tried to use several images from 50% to 5% with the condition while (while it find the image 50% or 45 % or 40% etc it press F3, but for some reason it isn't working
I thought that maybe if I use area size it could help..
Can someone give me a north?

Hi @Seabra - good to see you here!

Short answer is no I'm sorry to say.

To look for a visible object on the screen you have to tell KM what it is that object actually looks like and you are not doing that in the snippet you posted.

If I wanted to look for this:
KM 0 2021-06-07_10-27-10

I would use the Found Image condition like so:
KM 1 2021-06-07_10-32-12

To explain:

  1. Is the actual visible thing I want to search for: it's a screen grab of a progress bar and I've dropped the file into the image well.
  2. Is the "fuzziness" range which tells KM how accurately the screen and the image you've provided in (1) have to match. The smaller the fuzziness the more exactly they have to match.
  3. KM actions that need to happen while KM can "see" the searched-for object.

The percentage value that you're seeing in the green box is a measure of the fuzziness of the match that KM is detecting. It's nothing to do with the length of the progress bar. To illustrate,

with the fuzziness set to 0, we get this match:

KM 2 2021-06-07_10-30-07

and a fuzziness of about 90 we get this:

KM 3 2021-06-07_10-31-21

In this second example you can see the % value increasing from 0 to 58 as the found image becomes more different from the actual one being searched for.

You can access this % value that KM calculates by using information returned by KM. See the wiki page here collection:Found Images [Keyboard Maestro Wiki], but it is usually used as an indicator of "goodness" of match.

So given this, I'd say using the Found Image condition to detect a progress bar at 5%, 10%, 15% and so on would probably be achievable with the fuzziness set to 0 and with 10 different conditions to cover each of the separate progress bar images you have.

BUT - even though it would probably be possible it would result in a really unwieldy KM macro that, because it depends on "fuzziness", would not always be 100% reliable.

I would look for some other way of detecting the value of your "health". For example, how do you actually know that the progress bar is showing "5%"? Visually, that doesn't look much different from the progress bar at 10%. So, is the 5%, 10% etc displayed as a number somewhere else? If it is then there might be a better and more direct way for KM to "see" and extract that value and subsequently perform some actions.

2 Likes

great explanation Tiffle.

You can use a "Pause Until" action and place all the images as conditions if you need to press the same F3 for any found image:

or a "If then Else" if you need to press different X keys:

Note: If KM detects the image, KM is going to repeatedly press F3, as in, several times per second, so try adding Pause N seconds actions as well.

2 Likes

Thanks so much for your help, I think that it won't work as I was imagining then ;(
I was wondering, in my screen it also show in numbers like:
health points 220
mana: 150
Is it possible that KM recognise this numbers and calculate the percentage to use a hotkey ? for example when mana is 50% or less press F5 or something? Or I should just give up this?

It depends on the app you’re working with. Because it’s a game it’s unlikely that it will support AppleScript to extract those values. However, there’s GUI Scripting as an option that might let you get at the values.

What game is it? And are you familiar with GUI Scripting?

1 Like

Should be doable to recognize the number as an image that has the number, and as Tiffle mentions, use images for the actions.

ie in an If then Else action, you can place as conditions to detect if any of these images are present:

  • 50%
  • 40%
  • 30%

and then simulate F5 keystroke

2 Likes

Im afraid no, im very new to everything, I've started studying different things related to computer cause im saving money to do a university in computer science, this macros really make me excited to learn, its a simple 2d game that sometimes I play for fun.

I couldn't find how to use this parameter to recognise any of the images and press F5.
So basically I should make if then else action which every percentage and learn how to use this parameter to detect any of this images to press F5?
ill post a image of how the game looks like:

Theres a visual bar showing health points (6155) and it also shows in the skills windows as health points and mana.
I was trying to use the numbers to create a script but I couldn't do that, its hard to find something related to learn and try. I really appreciate everyones help!

Hey @Seabra - what's the game? Is there a free download? If there is we could do some testing for you!

2 Likes

Yes there is:
https://www.tibia.com/account/?subtopic=downloadclient
I really appreciate you help!!

Hi @Seabra - I see you need to create an account to actually play the game. That's not possible for me to do so I can't help you any further with that I'm sorry to say.

1 Like

can I send one for you?

Sorry - all work and no play makes tiffle dull!

you can do something like this:
image

Macro was uploaded in a disabled state, enable it to use.
Several Images.kmmacros (37.5 KB)

You might need to play around with the fuzziness (the slider) to catch other percentages.

2 Likes

I understand, thanks anyway :slight_smile:

1 Like

Ive tried your macro with different fuzziness without success, sometimes it shows (if I check display box) on screen but it didn't press F5.

How you use this images, is it from file? when I use images from file it shows different on macro

Ive tried different images:
50
45
40

Also like this:
MP5Percent
MP10Percent
MP15Percent
MP20Percent
MP25Percent
MP30Percent
MP35Percent
MP40Percent
MP45Percent
MP50Percent

Mana.kmmacros (4.4 KB)

Your macro is fine, two comments:

  1. Trigger
    Screen Shot 2021-06-09 at 10.51.38 AM

this means it will only run 1 time (when you switch to it)

  1. Also, try reducing the fuzziness to about the middle of the slider, since it currently triggers many false positives.

I just copy-pasted your images in the image container:
Mana-embeddedimages.kmmacros (81.3 KB)

but your approach works fine too, and might be even easier to maintain in the long run.

1 Like

Thanks so much, ill try again!
I found a script for windows, idk if I can use something here to help:

;==============================CONFIGURAÇÕES/CONFIGS==============================

;1) AUTO HEALING MANA:
;[ESTAGIO 1]
Porcentagem_Para_Healar_Mana = 80 ;Se sua [MANA] estiver abaixo desse valor o BOT ira Apertar a [Hotkey_de_ManaPotion]
Hotkey_de_ManaPotion = {2} ;Hotkey da MANAPotion no TIBIA!!! ira ser pressionada assim que a vida estiver abaixo do [Valor_Para_Healar_Mana]
Porcentagem_HP_Para_Ignorar_Mana = 45 ;PORCENTAGEM DE HP PARA PRIORIZAR A VIDA INVES DA MANA

;SE VOCE VAI USAR ESSE MACRO NO TIBIA GLOBAL DEIXE ATIVA A FUNÇÃO ABAIXO. ELA IRÁ DEIXAR SEU TIBIA TRANSPARENTE
WinSet, Transparent, 1, ahk_class Qt5QWindowOwnDCIcon

;!!!!!NAO EDITE NADA DAQUI PRA BAIXO!!!!!!
;!!!!!NAO EDITE NADA DAQUI PRA BAIXO!!!!!!
;!!!!!NAO EDITE NADA DAQUI PRA BAIXO!!!!!!
;!!!!!NAO EDITE NADA DAQUI PRA BAIXO!!!!!!
;!!!!!NAO EDITE NADA DAQUI PRA BAIXO!!!!!!
;!!!!!NAO EDITE NADA DAQUI PRA BAIXO!!!!!!
#NoEnv
#Warn
#SingleInstance Force
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
SendMode Input
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
Menu, Tray, Icon, Imagens\Mana_Potion.ico ; Change the tray icon

SetTimer, AutoHealingMana, 200 ;ler a cada 0,2segundos

;===LIFE=
AutoHealingMana:
If WinActive("ahk_class Qt5QWindowOwnDCIcon")
{
ImageSearch, FirstStageX, FirstStageY, A_ScreenWidth - 358, 0, A_ScreenWidth, A_ScreenHeight + 470, *15, Imagens\HP%Porcentagem_HP_Para_Ignorar_Mana%Percent.png ;% CHECAR HP
if ErrorLevel = 0
{
ImageSearch, SecondStageX, SecondStageY, A_ScreenWidth - 358, 0, A_ScreenWidth, A_ScreenHeight + 470, *15, Imagens\MP%Porcentagem_Para_Healar_Mana%Percent.png ;% Primeiro Estagio [MANA]
if ErrorLevel = 1
{
Send, %Hotkey_de_ManaPotion% ;Hotkey Primeiro Estagio [MANA]
Sleep 250
goto AutoHealingMana
}
}
}
return

;=HOTKEYS====
Home::
Pause
return

Hello, I didn't put any trigger now, but same thing is happening, when I press command tab to change windows from macro to the game it press 1 time F5 then it appears to stop :frowning:
Ive tried to add a continuous loop action at the end but same is happening.