Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Hey!
I haven't really used AHK much, but I'm playing some older games with very, very poor visual indicators. In fact, they are practically missing!
The only good visual indicator is an icon, which goes from grayed out when unavailable to colored.
I use 1, 2, 3 for attacks, but when the mob is buffed by magic, I need AHK to see that an icon has changed color, going from grayed to colored, and no matter if I'm pressing 1, 2, 3 (my basic attacks), AHK has to make me press g when it changes color, and it has to press it as a priority. So, the icon for dispelling now has color, but let's say, I'm still pressing 3 and AHK has go "NO! You're pressing g!".
I also have a different ability for dispelling myself, this has to be number 2 on the priority list.
So, g is available, g gets pressed, 4 is available (for is my ability that let's me dispel myself) it gets pressed second, even if I'm pressing 1, 2 or 3.
Of course I have a while lot of other buttons that I use, e for channeling abilities, z for finishers, etc. etc. so this only has to work on 1, 2 or 3.
I don't even know if I should be using AHK v2 or the other one.
I haven't really used AHK much, but I'm playing some older games with very, very poor visual indicators. In fact, they are practically missing!
The only good visual indicator is an icon, which goes from grayed out when unavailable to colored.
I use 1, 2, 3 for attacks, but when the mob is buffed by magic, I need AHK to see that an icon has changed color, going from grayed to colored, and no matter if I'm pressing 1, 2, 3 (my basic attacks), AHK has to make me press g when it changes color, and it has to press it as a priority. So, the icon for dispelling now has color, but let's say, I'm still pressing 3 and AHK has go "NO! You're pressing g!".
I also have a different ability for dispelling myself, this has to be number 2 on the priority list.
So, g is available, g gets pressed, 4 is available (for is my ability that let's me dispel myself) it gets pressed second, even if I'm pressing 1, 2 or 3.
Of course I have a while lot of other buttons that I use, e for channeling abilities, z for finishers, etc. etc. so this only has to work on 1, 2 or 3.
I don't even know if I should be using AHK v2 or the other one.
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Sorry about the bad typing in my post.
I did find something similar to what I've requested:
viewtopic.php?t=90354
But it didn't seem to work, so I'm guessing that searching by pixel color is impossible or maybe very difficult?
Also, how would I go about finding coordinates x and y, and get the color of the pixel in that area? Wouldn't I need some type of AHK script for that as well?
I did find something similar to what I've requested:
viewtopic.php?t=90354
But it didn't seem to work, so I'm guessing that searching by pixel color is impossible or maybe very difficult?
Also, how would I go about finding coordinates x and y, and get the color of the pixel in that area? Wouldn't I need some type of AHK script for that as well?
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
To answer your earlier question, you should be using v2 as it is the actively supported version.
Searching for a color is straightforward using PixelGetColor.
Not sure what you mean, but I think the answer to your question is to use the Window Spy tool that comes with AHK.
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Thank you for the help! I'm doing some progress.boiler wrote: ↑25 May 2024, 05:38To answer your earlier question, you should be using v2 as it is the actively supported version.
Searching for a color is straightforward using PixelGetColor.
Not sure what you mean, but I think the answer to your question is to use the Window Spy tool that comes with AHK.
I've tried out AutoHotkey Window Spy and when I hovered my mouse cursor over my grayed out icon it came up with the position 1385, 1302 this should be the x and y, axis correct?
It also did show the color 141414, so I'm guessing that this would be 0x141414, right?
So I have the the position and I have the color of the grayed out dispel icon.
Now when I'm pressing 1, 2 or 3 on my keyboard I need AHK to somehow notice that the color has changed to another one and when ever I press 1, 2 or 3 it has to make me press the "g" key. Something like:
Code: Select all
send {g Down}
send {g up}
The "g" key has to be the priority because there's also the "4" key, which is another different ability, which dispels myself, and 1, 2 and 3 keys are my main attacks.
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Generally, yes. You need to pay attention to whether it’s screen, window, or client coordinates and may need to use CoordMode to adjust accordingly.
Yes. So you would get the color of the known pixel location and compare the result to that value.
In v2, literal strings must be quoted. See the documentation for examples. What you showed would look like this:Patrycy wrote: ↑25 May 2024, 07:33Now when I'm pressing 1, 2 or 3 on my keyboard I need AHK to somehow notice that the color has changed to another one and when ever I press 1, 2 or 3 it has to make me press the "g" key. Something like:
Code: Select all
send {g Down} send {g up}
Code: Select all
Send '{g Down}'
Send '{g up}'
Code: Select all
Send 'g'
I’m not sure what you’re saying is needed, but it sounds like you would make these into hotkeys that when triggered, the would check the color of a pixel and send the G key when it should.
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Yes, check if the icon changes color and:
Just like you have said.Send '{g Down}'
Send '{g up}'
I'd like to try doing this with at least the "1" key for now.
Right now, ingame, 1 is just a normal slashing attack, but whenever the icon at 1385, 1302 changes color from 0x141414 to a different color, it has to check for it, and my next click, even if I press "1", has to be turned in to "g".
I also want to do the same for another ability, but "g" has to be a priority and "4" has to always be second on the priority list.
So let's say I'm attacking:
- The boss/mob gets buffed with magic
- I'm still pressing 1 on the keyboard
- AHK detects that "g" is available / icon (1385, 1302) changed color
- AHK presses "g" even if I am pressing 1, it essentially has to change "1" to "g" when the icon changes color
Scenario 2, I'm still attacking:
- The boss/mob uses a magic ability on me
- I'm still using "1" to attack
- AHK detects that "4" is available / different icon changed color
- Boss also just buffed himself
- AHK detects that "g" is available / icon (1385, 1302) changed color
- It first has to press "g" because "g" is an absolute priority and the boss has to be dispelled, then "4" because the negative effect applied to me it's less important, all while I'm still pressing "1"
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
I'm guessing it would have to start with something like:
Right?
But I honestly don't know much about coding, I'm not even sure if it is possible to create such a script.
Also, the whole priority thing, I'm not sure if that can be coded either.
Code: Select all
#Persistent
x := 1385, y := 1302
SetTimer, Check, 1000
But I honestly don't know much about coding, I'm not even sure if it is possible to create such a script.
Also, the whole priority thing, I'm not sure if that can be coded either.
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Yes, but checking only every second seems like it’s overly infrequent, but I don’t play this game — or any games.
Yes, it can be coded. That doesn’t mean your game will respond to virtual keypresses. Some don’t. So you should test that first.
- Noitalommi_2
- Posts: 332
- Joined: 16 Aug 2023, 10:58
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Hi.
Based on what I've read about this topic, here's an example script you could try out.
Based on what I've read about this topic, here's an example script you could try out.
Code: Select all
#Requires AutoHotkey 2.0
#SingleInstance
$1:: ; $ prefix to prevent that the hotkey trigger itself
$2::
$3:: {
if PixelGetColor(1385, 1302) = 0x141414 ; if Color is 0x141414 press 1,2 or 3
SendEvent "{" SubStr(ThisHotkey, 2) "}"
else ; if Color is not 0x141414 press g
SendEvent "{g}"
}
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Hey! Thanks for the help!Noitalommi_2 wrote: ↑26 May 2024, 07:31Hi.
Based on what I've read about this topic, here's an example script you could try out.
Code: Select all
#Requires AutoHotkey 2.0 #SingleInstance $1:: ; $ prefix to prevent that the hotkey trigger itself $2:: $3:: { if PixelGetColor(1385, 1302) = 0x141414 ; if Color is 0x141414 press 1,2 or 3 SendEvent "{" SubStr(ThisHotkey, 2) "}" else ; if Color is not 0x141414 press g SendEvent "{g}" }
I didn't want to attack a horrifically powerful enemy, so I went to some lower level mobs and tried to test out something similar.
Code: Select all
#Requires AutoHotkey 2.0
#SingleInstance
$1:: {
if PixelGetColor(1007, 1052) = 0xF0D64D ; if Color is 0xF0D64D press 1
SendEvent "{" SubStr(ThisHotkey, 2) "}"
else
SendEvent "{5}"
}
Problem is that the script kinda did and didn't work.
When I pressed the "1" key I didn't get my standard slash attack, so I had to defend myself with "2" and "3".
The only thing that happened when pressing "1" was that I was using my 15 second self buff which is assigned to my "5" key, so essentially the "1" key became my "5" key.
- Noitalommi_2
- Posts: 332
- Joined: 16 Aug 2023, 10:58
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
@Patrycy
PixelGetColor uses client coordinates unless otherwise specified with CoordMode.
Therefore, make sure you use the client coordinates provided by Window Spy.
PixelGetColor uses client coordinates unless otherwise specified with CoordMode.
Therefore, make sure you use the client coordinates provided by Window Spy.
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
Thank you! It worked! I rebound some keys and used:Noitalommi_2 wrote: ↑26 May 2024, 10:57@Patrycy
PixelGetColor uses client coordinates unless otherwise specified with CoordMode.
Therefore, make sure you use the client coordinates provided by Window Spy.
Code: Select all
#Requires AutoHotkey 2.0
#SingleInstance
$1:: {
if PixelGetColor(1012, 1052) = 0xEACD8D ; if Color is 0xEACD8D press 1
SendEvent "{" SubStr(ThisHotkey, 2) "}"
else
SendEvent "{4}"
}
But how do I expend on it?
I have rebound some keys again and tried:
Code: Select all
#Requires AutoHotkey 2.0
#SingleInstance
$1:: {
if PixelGetColor(1012, 1052) = 0xEACD8D ; if Color is 0xEACD8D press 1
SendEvent "{" SubStr(ThisHotkey, 2) "}"
else
SendEvent "{4}"
if PixelGetColor(1316, 1236) = 0x3D3B3D ; if Color is 0x3D3B3D press 1
SendEvent "{" SubStr(ThisHotkey, 2) "}"
else
SendEvent "{6}"
}
- Noitalommi_2
- Posts: 332
- Joined: 16 Aug 2023, 10:58
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
@Patrycy
Your second skript would always send two keys, but you only want to send one key per input.
Please try this:
The more PixelGetColor you insert, the larger the delay becomes because each PixelGetColor call takes a few ms. (about a frame length)
Your second skript would always send two keys, but you only want to send one key per input.
Please try this:
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
$1:: {
if PixelGetColor(1012, 1052) != 0xEACD8D ; if unequal 0xEACD8D send 4
SendEvent "{4}"
else if PixelGetColor(1316, 1236) != 0x3D3B3D ; if unequal 0x3D3B3D send 6
SendEvent "{6}"
; put another "else if" with SendEvent here
else ; else send 1 (if all skills are grayed out do the standard attack)
SendEvent "{1}"
}
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
I get that, but it's working really perfectly! Can I mix the two scrips together?Noitalommi_2 wrote: ↑26 May 2024, 21:13The more PixelGetColor you insert, the larger the delay becomes because each PixelGetColor call takes a few ms. (about a frame length)
Right now I'm using:
Code: Select all
$1:: {
if PixelGetColor(1005, 1058) != 0x99614D ; if Color is not 0x99614D press 4
SendEvent "{4}"
if PixelGetColor(1367, 1041) != 0xFFEB90 ; if Color is not 0xFFEB90 press 6
SendEvent "{6}"
else
SendEvent "{1}"
}
Also, can I mix both of the scrips? Add something like:
Code: Select all
$1:: {
if PixelGetColor(1174, 1294) = 0xF01A09 ; if Color is 0xF01A09 press 3
SendEvent "{" SubStr(ThisHotkey, 2) "}"
else
SendEvent "{3}"
}
I'm just asking because the icons for different abilities change appearance/color, so 3 can only be activated once it's very red.
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
@Noitalommi_2
Also, is there some way I can speed up the key presses? So there's less of a delay?
I was also thinking about something I've found previously:
And create something like:
viewtopic.php?t=45869
Then add Label 2 and 3
Problem is that I don't know how to write the whole Label thing in v2.
Anyway, I was thinking that if I can chop the whole thing in to little chunks, maybe I can quicken the whole script execution by adding Sleep 5000 to the mix? Because all of these abilities can be used every 5 seconds anyway. If the script knows that each of them can only be used only every few seconds, then maybe I can make it work much more smoothly? Or is there some other method to hasten the whole process? The animations also take about 0.3 to 0.4 of a second to finish.
Also, is there some way I can speed up the key presses? So there's less of a delay?
I was also thinking about something I've found previously:
Code: Select all
Label1:
if PixelGetColor(1384, 1304) != 0x0E0F0E
SendEvent "{g}"
return
viewtopic.php?t=45869
Then add Label 2 and 3
Problem is that I don't know how to write the whole Label thing in v2.
Anyway, I was thinking that if I can chop the whole thing in to little chunks, maybe I can quicken the whole script execution by adding Sleep 5000 to the mix? Because all of these abilities can be used every 5 seconds anyway. If the script knows that each of them can only be used only every few seconds, then maybe I can make it work much more smoothly? Or is there some other method to hasten the whole process? The animations also take about 0.3 to 0.4 of a second to finish.
- Noitalommi_2
- Posts: 332
- Joined: 16 Aug 2023, 10:58
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
@Patrycy
Key presses require a small delay for the game to recognize them.
If you mean the delay caused by calling PixelGetColor multiple times, you can reduce this with GetMultiPixelColor from here.
But I don't understand what you're trying to do right now, can you please briefly summarize what your script should do and please write the coordinates with the corresponding action then I can perhaps write a suitable script as an example.
Key presses require a small delay for the game to recognize them.
If you mean the delay caused by calling PixelGetColor multiple times, you can reduce this with GetMultiPixelColor from here.
But I don't understand what you're trying to do right now, can you please briefly summarize what your script should do and please write the coordinates with the corresponding action then I can perhaps write a suitable script as an example.
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
@Noitalommi_2
Right now I have respecced my character a bit, so I'll give you some details of what I'm currently using. Keep in mind that this game has a global cooldown because it's an Alpha Single Player version of WoW with custom content, interface and all kinds of super bizzare stuff.
https://www.youtube.com/watch?v=PW0vGqz1jXs&t=771s
I also switched some buttons around!
This is what I'm using currently for the script:
So "y" is now my single target dispel, the icon changes color when the ability is available because the target has a magical buff. In my current build, this ability has now a cooldown of 7 seconds, but I can make it 5 seconds or 10 seconds, depending on the spec.
"u" this is my buff, it now lasts 15 seconds and it increases my HP, also heals me
"i" is a stronger attack on a 10 second cooldown.
And finally the 4th part:
"o" and "1". "1" is of course my main attack that has no CD or anything, it's just a normal slash, but "o" is a special attack, it has no cooldown, but it requires me to build up rage (I have mana, rage and vigor as my resources), default rage is 0 and it grows as you fight, then spend it, and it can go down to 0, right now I have modified my interface to show rage in the form of an orb. It looks similar to this:
https://imgur.com/FR9S6e4
When attacks are on cooldown or not available (for example: due to a lack of rage or energy), the icons change color, so the only stable icon that's always the same color is assigned to the "1" key. They become a bit darker or grayed out like this, plus there's a small cooldown timer on the bottom, similar to this:
https://cdn-wow.mmoui.com/preview/pvw58541.jpg
The whole code I'm using now looks like this:
It's works, but it's just slow, that's why I'd like to speed it up or add some sleep, so that the scrip won't have to check so much, like Sleep 7000 for "y" or Sleep 5000 if I spec more in to dispelling more. Most of these abilities do have cooldowns anyway, and depending on my talents the wait times can be shortened or made longer.
It seems very complicated, should I try to copy / paste some of this in to my code?Noitalommi_2 wrote: ↑28 May 2024, 05:18Key presses require a small delay for the game to recognize them.
If you mean the delay caused by calling PixelGetColor multiple times, you can reduce this with GetMultiPixelColor from here.
I'll try.Noitalommi_2 wrote: ↑28 May 2024, 05:18But I don't understand what you're trying to do right now, can you please briefly summarize what your script should do and please write the coordinates with the corresponding action then I can perhaps write a suitable script as an example.
Right now I have respecced my character a bit, so I'll give you some details of what I'm currently using. Keep in mind that this game has a global cooldown because it's an Alpha Single Player version of WoW with custom content, interface and all kinds of super bizzare stuff.
https://www.youtube.com/watch?v=PW0vGqz1jXs&t=771s
I also switched some buttons around!
This is what I'm using currently for the script:
Code: Select all
if PixelGetColor(1384, 1304) != 0x0E0F0E
SendEvent "{y}"
Code: Select all
else if PixelGetColor(1005, 1058) != 0x99614D
SendEvent "{u}"
Code: Select all
else if PixelGetColor(1366, 1040) != 0xE65217
SendEvent "{i}"
And finally the 4th part:
Code: Select all
else if PixelGetColor(1411, 1043) != 0x863BDD
SendEvent "{o}"
else
SendEvent "{1}"
https://imgur.com/FR9S6e4
When attacks are on cooldown or not available (for example: due to a lack of rage or energy), the icons change color, so the only stable icon that's always the same color is assigned to the "1" key. They become a bit darker or grayed out like this, plus there's a small cooldown timer on the bottom, similar to this:
https://cdn-wow.mmoui.com/preview/pvw58541.jpg
The whole code I'm using now looks like this:
Code: Select all
#Requires AutoHotkey 2.0
#SingleInstance
*~$1:: {
if PixelGetColor(1384, 1304) != 0x0E0F0E
SendEvent "{y}"
else if PixelGetColor(1005, 1058) != 0x99614D
SendEvent "{u}"
else if PixelGetColor(1366, 1040) != 0xE65217
SendEvent "{i}"
else if PixelGetColor(1411, 1043) != 0x863BDD
SendEvent "{o}"
else
SendEvent "{1}"
}
- Noitalommi_2
- Posts: 332
- Joined: 16 Aug 2023, 10:58
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
@Patrycy
Your last script needs around 67ms with all "else if" calls on my PC and I wouldn't call it slow, especially since the global cooldown in WoW is around 1.5s.
And I don't know how the script could be made noticeably faster, as the number of PixelGetColor calls is just to small. I mean, you could probably make it a little faster, but I doubt it would make much of a difference if the script ran 20ms faster.
What can cause problems is the tilde prefix, because it sends the original key of the hotkey before all pixels have been checked and I think that even triggers the global cooldown in the game, right?
You should not use the tilde prefix in this case and if you use the asterisk then there is no need for the $-prefix.
So this would be enough *1::
How fast does the script runs on your end?
Here's how you can test it:
Your last script needs around 67ms with all "else if" calls on my PC and I wouldn't call it slow, especially since the global cooldown in WoW is around 1.5s.
And I don't know how the script could be made noticeably faster, as the number of PixelGetColor calls is just to small. I mean, you could probably make it a little faster, but I doubt it would make much of a difference if the script ran 20ms faster.
What can cause problems is the tilde prefix, because it sends the original key of the hotkey before all pixels have been checked and I think that even triggers the global cooldown in the game, right?
You should not use the tilde prefix in this case and if you use the asterisk then there is no need for the $-prefix.
So this would be enough *1::
How fast does the script runs on your end?
Here's how you can test it:
Code: Select all
*1:: {
start := A_Tickcount
if PixelGetColor(1302, 1393) != 0x4E5A2B
SendEvent "{y}"
else if PixelGetColor(1131, 1534) != 0xFFD970
SendEvent "{u}"
else if PixelGetColor(1302, 1681) != 0xE0E0E0
SendEvent "{i}"
else if PixelGetColor(1142, 1817) != 0x006600
SendEvent "{o}"
else
SendEvent "{1}"
ToolTip A_TickCount-start "ms"
}
Re: Can AHK decect a chnage in pixel color? Clicking icon/ability in game.
@Noitalommi_2
I have just tried it out, the most I get is about 63 ms and the least I get is about 17 ms, the whole thing is a bit inconsistent, if I could make it a little bit faster by that 20 ms that would be absolutely incredible! I don't know why, but the whole thing feels a bit unresponsive. I'm just noticing it as I play.
I have just tried it out, the most I get is about 63 ms and the least I get is about 17 ms, the whole thing is a bit inconsistent, if I could make it a little bit faster by that 20 ms that would be absolutely incredible! I don't know why, but the whole thing feels a bit unresponsive. I'm just noticing it as I play.