Sign in to follow this  
Followers 0
Guest Nevets

Please Help Newbie

16 posts in this topic

I'm a first time scripter, no history in programming or anything so I'm just doing a hackjob, so far I've had good progress. I need my script to determine if a certain pixel, coordinates (503, 206) (window) is the color 0x277FEF. Then if the pixel is that color then click on it, if the pixel is not that color, to wait until it turns that color then click on it as soon as it does. If you can get me to this stage I Can do the rest. Thank you.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You have several aspects to your script that you want, and it helps to outline them as simple goals before you start so you can begin to layout your code. You have:

  • A condition to match (the pixel)
  • An action to do when the match is positive (the click)
  • A loop to continue if the match is negative (the "waiting")
The looping, can be found in the AutoIt help file (called AutoIt.chm) in the AutoIt: Language Referance: Loop Statements section, and I'd highly recomend you read that section to understand the various looping functions. Actually, if you are new to codding AutoIt, you may want to read all the Using AutoIt and Language Referance sections to understand better how it works.

Since you want to wait while the pixel is not your color, a while loop will do what you want. (See also the while loop in the helpfile for specific information on this type of loop.)

Now that we have the basic loop that we will use, we need to decide what the loop will do. You want to test for the pixel match , and there is a PixelGetColor function (again, read about it in the helpfile!) There is also an If instruction to conditionally run code (see the AutoIt: Language Referance: Conditional Statements section.)

You also need a mouseclick. We have a MouseClick function (see helpfile for info.) You may also wish to look at the ControlClick function for the ability to click without the window needing to be active.

One last note: when running any form of a loop that will do nothing but wait until an event occurs, you should always include a pause to prevent your CPU from maxing itself out. Otherwise your computer will work very very hard at checking the condition about 100 times per second.

Now, I've put all this together for you into a code segment below with comments. Again, please read about each of these functions and methods in the helpfile.

;While the pixel doesn't match our color number:
While PixelGetColor(503, 206) <> 0x277FEF
  Sleep(100);wait 1/10th of a second, and check again
WEnd
;at this poit in the code, the pixel does match
;we now want to click that position
MouseClick("left", 503, 206)

Edited to make it sound more readable

Edit on 06-08-04 @ 16:08 CDT to fix the MouseClick function so it works

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

If someone can show me an example of this I would be very greatful. All I need is an example program that does the following:

I need my script to determine if a certain pixel, coordinates (503, 206) (window) is the color 0x277FEF.  Then if the pixel is that color then click on it, if the pixel is not that color, to wait until it turns that color then click on it as soon as it does.

I would be very greatful. Thank you for all your help. I'm sorry but I work best with examples and I'm trying to learn this the easy way just so I can make programs that do this function over and over. Thanks!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If someone can show me an example of this I would be very greatful. All I need is an example program that does the following:

Um... did you even look at my post above??? The code is at the bottom of the post, with comments to explain what is happening. Did you try it? It does excatally what you asked. I also explained very compleatly the throught process you should try and use in the future when codding something.

Also, I referanced each command I used to the HelpFile. Read that. It will help, a lot.

[Edit]:

I'm trying to learn this the easy way just so I can make programs that do this function over and over.

The "easy way" is to learn how to do it yourself so you don't have to come back to this forum every time you want to do something you don't know how to do. It also appears like you may want to do that function I posted above over and over. I'm not going to give you code to do that, because after reading the sections in the helpfile that I pointed out, you should really be able to do it yourself. Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Yes I read your post but I threw that in my code and no avail. Would you like to see what I have so far?

Share this post


Link to post
Share on other sites

Yes I read your post but I threw that in my code and no avail.  Would you like to see what I have so far?

:D

The code's pekster not work? Did you tried it?

Use a MsgBox or "DebugMode" if you don't see something when you running the script.

Share this post


Link to post
Share on other sites

It hovers the mouse over it and it doesn't make the click. I don't know why, here's what I got.

Opt ( "MouseCoordMode", 0 )

WinActivate("*** ***** ******")

MouseMove( 368, 229, .2 )

MouseClick ( "left" , 368, 229, 1)

WinActivate("**** ********")

MouseMove( 199, 63, .2 )

MouseClick ( "left" , 199, 63, 1)

While PixelGetColor( 503, 206 ) <> 0x277FEF

Sleep( 100 )

WEnd

MouseMove( 503, 206, .2 )

MouseClick ( "left" , 503, 206, 1)

Share this post


Link to post
Share on other sites

Figured it out, new question though. How can I make my program wait for a window named "Window1" to pop up but at the same time if a different window pops up named "Window2" it activates Window2 and does a mouseclick but if Window1 comes up it activates Window1 and does a mouseclick. Do I use a WHILE statement? If so maybe throw in an example of this. I'm almost complete with my script so thanks for all the help you guys gave me!

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

While 1

If WinExists("Window1") Then

If WinExists("Window2") Then WinActivate("Window2")

EndIf

Sleep(1000) ; Sleep one second

WEnd

I didn't understand how you want it exactly, but it's a start.

Edited by SlimShady

Share this post


Link to post
Share on other sites

Thanks Slim, this is a good foundation to start what I need to do! You rock!

Share this post


Link to post
Share on other sites

Thanks Slim, this is a good foundation to start what I need to do! You rock!

Share this post


Link to post
Share on other sites

Sorry my macro went crazy and made that repost... I can't figure out how to make it terminate when I hit a button, lol. It gets stuck in the loop.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I can't figure out how to make it terminate when I hit a button, lol. It gets stuck in the loop.

Use a hotkey in scripts you wish to terminate if it behaves how it shouldn't:

HotKeyEnable("{F10}", "abort")

;rest of your script goes here

Func abort()
  MsgBox(0, "Terminated", "You terminated the script.  Now exiting...")
  Exit
EndFunc

Edited to correct a typo

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Is there anyway I can contact you, AIM possibly Pek? It is difficult for me to explain what I'm trying to do.

Share this post


Link to post
Share on other sites

Is there anyway I can contact you, AIM possibly Pek?

Register with these forums and I'll PM you my AIM account. I don't like having that information on a public website where search engines or bots could find it.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0