Short Script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Elequosoraptor

Short Script

Post by Elequosoraptor » 11 Oct 2017, 09:03

Loop
{
PixelSearch, 931, 633, 1053, 792, 0x00204, 3, Fast
{
Send, {LButton}
Sleep 800
Send, {LButton}
Return
}
else
Send k
}

Esc::ExitApp
Return

User avatar
Delta Pythagorean
Posts: 628
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Short Script

Post by Delta Pythagorean » 11 Oct 2017, 09:39

What are you asking? There's no question or anything connected to this. I'm afraid I'm going to have to report this. Sorry bud.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat


User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Short Script

Post by Exaskryz » 11 Oct 2017, 10:27

I see several mistakes here.

PixelSearch's color is not 6 digits long. I don't know if 5 digits works, AHK may assume the input was 0x000204 (adding a 0 out front; like how 010 = 10). You've also not included the OutputX and OutputY parameters which are required. Well, technically you did, but not right. See, the first parameter is unambiguously OutputVarX. So you're saying AHK should store the result of the found pixel's X-coordinate in the variable 931 (accessed by %931%). Pure numbers as variable names are confusing, but, if you want to do that, you can. Same to the Y-coordinate being stored in variable 633. And then that 1053 says this is the X-coordinate of the first corner of the search region; 792 is the Y-coordinate of the first corner. Then 0x00204, as hexadecimal number -- it's 516 in decimal -- is being defined as the X-coordinate of the second corner. And then the 3 is the Y-coordinate of the second corner. So your search region is actually a lot larger than you expected. And finally, the color "Fast" is being used; Fast isn't a color, so it's a variable being evaluated as empty (you never defined it), and I assume that if PixelSearch accepts it, it would treat it as Black. (0x000000.)

There is no If statement, while there's an else statement. Most people use If !ErrorLevel to indicate a success happened with PixelSearch; the ! is the logical-not operator.

Now, as you're in a Loop, that right now has If statement, that would mean (despite AHK giving you an error about an else with no paired If) that you would hit the Return. That ends the loop immediately. If you want the result to be an indefinite number of k's and then two left clicks and then stop, your code is fine. But if you want the possibility of more than just those 2 clicks, you'd need to get rid of the Return.

Elequosoraptor
Posts: 18
Joined: 11 Oct 2017, 09:04

Re: Short Script

Post by Elequosoraptor » 11 Oct 2017, 14:44

Hey Thank You. I couldn't figure out how to write comments on my orginal post and then it got sent through by accident and I was a guest. It's a mess.

Loop
{
PixelSearch, 2, 7, 931, 633, 1053, 659, 0x3e3137, 3, Fast
if !ErrorLevel
{
Send, {LButton}
Sleep 800
Send, {LButton}

}
else
Sleep 10
}

Esc::ExitApp
Return

This is my updated code. Thanks again for the tips it's sort of working now. My original goal was to trigger the left clicks when an animation plays, its just a little project that basically autoruns part of a flash game. It's not important. However, it's still not triggering when it should. I still don't understand what the Output X and Y parameters do exactly, here I've just had them as random numbers. And the color code, I keep seeing that it should be in BRG format, but the examples seem to bein hexadecimal, and I really just don't know what to put there. Up there is the hexadecimal code for the color, with a 0x in front like in the examples on the tutorial. Thank you for helping. No obligation to continue.

Elequosoraptor
Posts: 18
Joined: 11 Oct 2017, 09:04

Re: Short Script

Post by Elequosoraptor » 11 Oct 2017, 14:44

Hey Thank You. I couldn't figure out how to write comments on my orginal post and then it got sent through by accident and I was a guest. It's a mess.

Loop
{
PixelSearch, 2, 7, 931, 633, 1053, 659, 0x3e3137, 3, Fast
if !ErrorLevel
{
Send, {LButton}
Sleep 800
Send, {LButton}

}
else
Sleep 10
}

Esc::ExitApp
Return

This is my updated code. Thanks again for the tips it's sort of working now. My original goal was to trigger the left clicks when an animation plays, its just a little project that basically autoruns part of a flash game. It's not important. However, it's still not triggering when it should. I still don't understand what the Output X and Y parameters do exactly, here I've just had them as random numbers. And the color code, I keep seeing that it should be in BRG format, but the examples seem to bein hexadecimal, and I really just don't know what to put there. Up there is the hexadecimal code for the color, with a 0x in front like in the examples on the tutorial. Thank you for helping. No obligation to continue.

User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Short Script

Post by Exaskryz » 11 Oct 2017, 15:08

OutputVarX and OutputVarY are meant to be variable names. Some people use PixelSearch and would move their mouse (MouseMove) to that pixel. They report where the pixel is.

Code: Select all

PixelSearch, MyX, MyY, 931, 633, 1053, 659, 0x3e3137, 3, Fast
MsgBox X: %MyX%`nY: %MyY%
You have it right that PixelSearch takes colors in the BGR format. Most programs uses RGB, so it's a common point of confusion. You're right to pass in a hexadecimal number. If you'd like to use RGB, I recommend using the RGB parameter. Change the Fast to Fast RGB.

As for it not working all the time, it depends on the speed of the animation. If the animation is really fast, then AHK might be too slow to see it. The way to speed it up would be to narrow the search area, if possible. A faster search means it can keep repeating search as quickly as possible. And to that end, you may be interested in changing the Sleep 10 and making it Sleep -1 which is the shortest possible sleep. (Desirable to still have a sleep at all because AHK can become unresponsive to your other hotkeys; the Esc::ExitApp may not work.)

Elequosoraptor
Posts: 18
Joined: 11 Oct 2017, 09:04

Re: Short Script

Post by Elequosoraptor » 11 Oct 2017, 16:35

Yes I've run into the problem with not having some delay. Currently, I can't seem to get the right size box. Is there a way to set up the if function, but with PixelGetColor? That way I can monitor the change of a specific pixel.

User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Short Script

Post by Exaskryz » 11 Oct 2017, 16:51

Yes. With PixelGetColor, you can check the reported value if an If statement. If (var="0x3e3137"). For the sake of testing the script, I recommend using a Tooltip or MsgBox to display the value of %var% or whichever name you give it.

Elequosoraptor
Posts: 18
Joined: 11 Oct 2017, 09:04

Re: Short Script

Post by Elequosoraptor » 11 Oct 2017, 17:12

Hells Bells I got it working. Thank you so much this has been super helpful. Really, this has plagued me literally constantly for the last 10 hours. Thank you.

Post Reply

Return to “Ask for Help (v1)”