Jump to content

Is this possible?


Recommended Posts

i want to make a program that can "sense" things,

this are some stuff i hope are possible it can do:

1.) lets use 100,100 as example co-ords. i want the program to "check" that spot for a color lets say 000000. and when its 000000 it does a set of commands, and if its another color, it does another set of commands, and it its another color it does nothing...

this probably need those "ifs" commands im totally clueless.... ive only gone far enough to move mouse and make it click ><

Link to comment
Share on other sites

no thats not what i mean well not atleast the main point....

i need help doing a functions that :

check X,Y

if x,y is "color", then do this, if not do nothing

if x,y is "color2" then do this , if not do nothing

if x.y is "color 3" then do this, if not do nothing

repeat again and again

Link to comment
Share on other sites

Ok, then you'll also want to search the help file for an If ... Then Satement. But if you use all those things:

While 1
  $color = PixelGetColor(x, y)
  If $color = [The Color You Are Looking For] Then
    [Code to do what you want]
  Else
    [Code to do something else, if you want[
  EndIf
Wend

Something like that should take care of you.

Ian

Edit: Formated the Code...

Edited by ioliver

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

well, that's exactly waht PixelSearch does... heres an example:

While 1
HotKeySet("^!p", "MyExit");PRESS CTRL+ALT+P TO EXIT!

while 1;starts loop
$coord = PixelSearch (x, x, y, y, 0xff0000, 0, 10);searches for pure red for every 10 pixels
If Not @error Then;if the color is found
MouseClick ("left", $coord[0], $coord[1], 1, 0);...if the color is found mouseclick where it was found
EndIf;ends if statement
wend;gose back to while 1

Func MyExit();exit func (user defined) 
Exit 
EndFunc

EDIT: added :idiot:

Edited by layer
FootbaG
Link to comment
Share on other sites

While 1

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

[Code to do what you want]

Else

[Code to do something else, if you want[

EndIf

Wend

so...... if i want to do more then one

While 1

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

[Code to do what you want]

Else

[Code to do something else, if you want[

EndIf

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

[Code to do what you want]

Else

[Code to do something else, if you want[

EndIf

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

[Code to do what you want]

Else

[Code to do something else, if you want[

EndIf

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

[Code to do what you want]

Else

[Code to do something else, if you want[

EndIf

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

[Code to do what you want]

Else

[Code to do something else, if you want[

EndIf

Wend

is that correct?

[Code to do what you want]

how would that be on note pad? should i copy and paste or should there be no space and have ; before it

Edited by lilandywandy
Link to comment
Share on other sites

If you a specific action to perform for more than one color, I would put the whole thing in a While ... Wend loop. And use Select ... Case to perform the actions.

[Code to do what you want]how would that be on note pad? should i copy and paste or should there be no space and have ; before it

The [Code to do what you want] is just refering to the actions you want the Script to perform, if it finds the correct color. For example, if the script finds the right color you might want it to Run() a program or Send() some keystrokes.

Check out the Bolded topics in the help file. It should give you a good place to start.

Ian

Edit: Corrected Misspelling

Edited by ioliver

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

While 1

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For]Then

  [Code to do what you want]

Else

  [Code to do something else, if you want[

EndIf

Wend

lets say i want to do more then one of those, where owuld the endif and wend be? like this?

While 1

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For]Then

  [Code to do what you want]

Else

  [Code to do something else, if you want]

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

  [Code to do what you want]

Else

  [Code to do something else, if you want]

EndIf

Wend

Link to comment
Share on other sites

Lilandywandy, That's good, but you can't start a second If statement without closing the first If statement with and EndIf. (Well, you can, but that would be a nested loop, and that's not what you were trying to do here.)

You code is:

While 1

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

  [Code to do what you want]

Else

  [Code to do something else, if you want]

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

  [Code to do what you want]

Else

  [Code to do something else, if you want]

EndIf

Wend

You have two If statements, and only one EndIf, so the Script will break. Try this instead:

While 1

$color = PixelGetColor(x, y)

If $color = [The Color You Are Looking For] Then

  [Code to do what you want]

Else

  [Code to do something else, if you want]

$color = PixelGetColor(x, y)

EndIf

If $color = [The Color You Are Looking For] Then

  [Code to do what you want]

Else

  [Code to do something else, if you want]

EndIf

Wend

Notice that each If statement is closed with and EndIf.

Hope that helps,

Ian

If you can describle some more about what you want to do, I may be able to come up with some better sample code.

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

Here's some sample code I put together that should work, and should help to get you started...

; Your resolution should be set to 1024 x 768 for this to work
; I haven't checked it whith other resolutions.
; To use this try painting the Box either White or Black...

Run("c:\windows\system32\mspaint.exe", "", @SW_MAXIMIZE)
While 1
   $color = PixelGetColor(600, 225)
   If $color = "16777215" Then; 16777215 = White
      MsgBox(1, "Color", "White", 3)
   EndIf
   If $color = "0" Then; 0 = Black
      MsgBox(1, "Color", "Black", 3)
   EndIf
Sleep(1000)
WEnd

Hope that helps,

Ian

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

Also make sure you have a sleep delay inside the loop, so it doesn't lag the computer too much.

Try using a select/case setup:

Select
    Case $color = xxxxx
       ;do stuff here
    Case $color = xxxxx
       ;do stuff here
    Case $color = xxxxx
       ;do stuff here
EndSelect

I think that's a lot cleaner then a bunch of If's :idiot:

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

lets say i want to do more then one of those, where owuld the endif and wend be? like this?

<{POST_SNAPBACK}>

i think this is what im trying to do but i dont dig you, : =(

let me see if i can be lil more detailed

i have 2 specific points on my desktop,

i want the computer to check its colors every 5 secs

[first coord]if the color is grey then it does "blah"

if the color is white then it does "blah"

it the color is blue then it does "blah" [end of first coord]

[2nd coord]if the color is brown then it does "blah" if not brown do nothing

Link to comment
Share on other sites

[first coord]if the color is grey then it does "blah"

[2nd coord]if the color is brown then it does "blah" if not brown do nothing

Because PixelGetColor(), returns the Dec. value of the color, you will need to know the Dec. value of 'Grey' and 'Brown'. To find the Dec. value of a color, download xDrop.

Untested Code:

While 1
  $color1 = PixelGetColor(first-coord-x, first-coord-y)
  If $color1 = [Dec. Value for Grey] Then
    [Code to do what you want]
  EndIf
  $color2 = PixelGetColor(second-coord-x, second-coord-y)
  If $color2 = [Dec. Value for Brown] Then
    [Code Here]
  EndIf
  Sleep(50)
WEnd

Like I said, untested, but's that the general idea.

Hope that helps,

Ian

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

Because PixelGetColor(), returns the Dec. value of the color, you will need to know the Dec. value of 'Grey' and 'Brown'. To find the Dec. value of a color, download xDrop.

to find out the decimal value of the color, hold your mouse over it, and use the autoit window spy.

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

to find out the decimal value of the color, hold your mouse over it, and use the autoit window spy.

Thanks t0ddie, I haven't used AutoIt Spy much, I didn't realize it could do that. But, that would be a better way.

Thanks again,

Ian

Edit: Made some formatting changes.

Edited by ioliver

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Link to comment
Share on other sites

CODE

Dim $blue = 255 ; pure blue #0000FF

Dim $gray = 8421504 ; Middle gray #808080

Dim $black = 0 ; pure black #000000

Dim $brown = 8932100 ; My version of brown #884B04

Dim $sec = 1000 ; Shortuct for sleep timers.

While 1

PixelGetColor($x, $y)

Select

Case $pixel = $blue

; do blah

Case $pixel = $gray

; do blah-blah

Case $pixel = $black

; do blibbity

Case $pixel = $brown

; do bobbity

EndSelect

Sleep($sec * 5)

WEnd

Define $x and $y on your own. :idiot:

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

  • Administrators

Why not just drop the decimals and do:

Dim $blue = 0x0000FF; pure blue #0000FF

:idiot:

Edit: And if you are not already, check out the beta SPY at http://www.autoitscript.com/autoit3/files/...oit/AU3_Spy.exe

It has a maginfying glass and everything :D

Edited by Jon
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...