Sign in to follow this  
Followers 0
ffxionline

If Pixel Get Color Then Play Sound..

15 posts in this topic

#1 ·  Posted (edited)

I am very new to auto IT and would like to see some examples of what I need acomplish. I looked through the auto it help file and found the commands I need to use. I want a script that will sit and wait infinetly untill a certain pixel color comes on screen and from that activate a wave file sound to play while still keeping the script running so it wont terminate the sound file. I think you start it something like

If PixelGetColor(?,?) = ??? Then

SoundPlay("C:\Windows\media\tada.wav")

but I am not sure if this is correct and dont know how to make it sit and wait untill this happens. I am sure this is incredibly easy to do if someone could write the exact way you do this that would be great.

Ok after experimenting this is what I cam up with.

$var=1

While $var > 0

If PixelGetColor(144,90) = 65535 Then

$var=1

SoundPlay("C:\Documents and Settings\Owner\My Documents\Direct Connect Downloads\Complete\1990 Deicide\Deicide - Deicide - 02 - Sacrificial Suicide.mp3")

EndIf

WEnd

The problem is that the song doesnt start playing when the pixel color appears but starts playing after I exit the screen. How can i make it play when it first appears and then have it keep playing untill I exit the script.

Edited by ffxionline

Share this post


Link to post
Share on other sites



You have it pretty much already.

This code will mark down the x,y of your mouse and the color under it when you hit the pause key. the options are dependant on your application. After, you could do it quite easy in one line.

Opt("MouseCoordMode", 1)       ;1=absolute, 0=relative
Opt("PixelCoordMode", 1)       ;1=absolute, 0=relative
Opt("TrayIconDebug", 1)        ;0=no info, 1=debug line info

hotkeyset("{pause}","setit")
global $pos[2],$color
while 1
If PixelGetColor($pos[0],$pos[1]) = $color Then 
SoundPlay("C:\Windows\media\tada.wav")
msgbox(1,$color,$pos[0]&@crlf&$pos[1])
exitloop

endif
sleep(500)
wend
clipput("color="&$color&@crlf&"x="&$pos[0]&@crlf&"y="&$pos[1])

func setit()

$pos=MouseGetPos ( )
$color=PixelGetColor ( $pos[0] , $pos[1])
endfunc

$x=100
$y=10
$color=16776183
If PixelGetColor($x,$y) = $color Then SoundPlay("C:\Windows\media\tada.wav")

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

I have a few scripts that use pixel color to determine other actions.

; bunch of code....
while PixelGetColor(100,100) <>16776183
sleep(10)
wend
SoundPlay("C:\Windows\media\tada.wav")
; do stuff

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Either of these codes seem to work for me. I have auto it 3.092 beta. Ok after experimenting this is what I cam up with.

$var=1

While $var > 0

If PixelGetColor(144,90) = 65535 Then

$var=1

SoundPlay("C:\Documents and Settings\Owner\My Documents\Direct Connect Downloads\Complete\1990 Deicide\Deicide - Deicide - 02 - Sacrificial Suicide.mp3")

EndIf

WEnd

The problem is that the song doesnt start playing when the pixel color appears but starts playing after I exit the screen. How can i make it play when it first appears on the screen and then have it keep playing untill I manually exit the script.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Can anyone else help me so that constanly searches for the color and then when it does it plays the file untill I manually exit the script.

Edited:

Ok I got it to work perfectly except I receieve an error in line 3 saying Illegal text at the end of statement (one statement per line).

$var=1

while $var > 0

If PixelGetColor(144,90) = 65535 Then SoundPlay("C:\Documents and Settings\Owner\My Documents\Direct Connect Downloads\Complete\1990 Deicide\Deicide - Deicide - 02 - Sacrificial Suicide.mp3") [, wait] )

Wend

After I exit the error the songs stops playing and the script exits. How can I fix this.

Edited by ffxionline

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If PixelGetColor(144,90) = 65535 Then SoundPlay("C:\Documents and Settings\Owner\My Documents\Direct Connect Downloads\Complete\1990 Deicide\Deicide - Deicide - 02 - Sacrificial Suicide.mp3") [, wait] )

two things, you have

) [, wait] )
at the end

you ended the function ) and then had the optional callout.

AutoIt thinks you have two functions.

second thing:

wait (optional) This flag determines if the script should wait for the sound to finish before continuing:

1 = wait until sound has finished

0 = continue script while sound is playing (default)

Optional means you can take out what is in the brackets, but you can't leave in the bracket. Ex:

If PixelGetColor(144,90) = 65535 Then SoundPlay("C:\Documents and Settings\Owner\My Documents\Direct Connect Downloads\Complete\1990 Deicide\Deicide - Deicide - 02 - Sacrificial Suicide.mp3")

or give it a value

If PixelGetColor(144,90) = 65535 Then SoundPlay("C:\Documents and Settings\Owner\My Documents\Direct Connect Downloads\Complete\1990 Deicide\Deicide - Deicide - 02 - Sacrificial Suicide.mp3" ,1)

edit.. oh yea, make sure you put a tiny sleep in or your CPU will be 100%.

replace:

wend

with:

sleep(10)

wend

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

OK thanks works great. Now I was wondering if there is a simple script that will allow you to run it and it will record the PixelGetColor(144,90) = 65535 ( the coordinates and color value) while in a application where you cant see the window spy. I am trying to record with windowspy but cant run both at the same time thanks.

Edited by ffxionline

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

When I was reading ffxionline's post I saw that he was trying to use

mp3-files with SoundPlay, and I thought that was the problem..

(As I've had problem with it myself..)

But it looks like that wasn't the problem, so, I guess it's only me

who have problems playing mp3-files with SoundPlay..

:whistle:

Edited by Helge

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

OK thanks works great.  Now I was wondering if there is a simple script that will allow you to run it and it will record the PixelGetColor(144,90) = 65535 ( the coordinates and color value) while in a application where you cant see the window spy.  I am trying to record with windowspy but cant run both at the same time thanks.

Is there a way to find the pixel color value and the coordinates in a game without using window spy as I cant see windowspy when im running a game. I would just take a screenshot but fraps only takes 1024x768 shots and I need the coordinate in a much higher resolution. How would I go about getting these coordinates is there a script that will record this information? Also I am not sure if there is a better way and going about the task I am trying to perform. Would possibly constantely searching for a pixel color and then playing the song when it finds this color be a better way to go about this maybe eliminating the resolution problem. How would I go about putting a search for pixel color in the script and to then play the song . Here is my code

$var=1
while $var > 0 
If PixelGetColor(144,90) = 65535 Then SoundPlay("C:\Documents and Settings\Owner\My Documents\Direct Connect Downloads\Complete\1990 Deicide\Deicide - Deicide - 02 - Sacrificial Suicide.mp3" ,1)
sleep(10)
Wend


            
                


    Edited  by ffxionline
    
    

            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
KnowledgeSponge   

    
        
    
             0
    
        
    

        
            
                Wayfarer
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             0
    
        
    

                63 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #10 · 
            Posted 
            
            
            
        
    

    


            
        
            Download Fraps.  Take screenshot in game.  I wrote this code to autoget colors and set up pixsearch or pixget, it writes the lines of code for you and you can just paste it into your script.  Can use it if you want.

$done = 0;
$exit = 1;
$exiting = 0;
Global $ks1 = "!1";
Global $ks2 = "!2";
Global $number = 0;
Global $clip = 0;
$loopit = 1;

;=======================Main Loop===============================

While $loopit > 0;

    Main()

WEnd

;=======================PixSearch===============================

Func PixSearch()

HotKeySet($ks1)
HotKeySet($ks2)

Global $file = FileOpen("autopix.txt", 2)
Global $spreadx = InputBox("PixelSearch Input", "PixelSearch Horizontal Spread?", "10")
Global $spready = InputBox("PixelSearch Input", "PixelSearch Vertical Spread?", "5")
Global $shadevariation = InputBox("PixelSearch Input", "PixelSearch Shade Variation?", "0")
Global $step = InputBox("PixelSearch Input", "PixelSearch Step?" & @CRLF & @CRLF & "After clicking OK, press ALT + 1 to set the point.", "1")

Do

    HotKeySet($ks1, "Searchit")

Until $exit = 1

EndFunc

;======================PixColor=================================

Func PixColor()

HotKeySet($ks1)
HotKeySet($ks2)

Global $file = FileOpen("autopix.txt", 2)
Global $points = InputBox("PixelGet Input", "How many points do you want to set?" & @CRLF & @CRLF & "After clicking OK, press ALT + 1 to set each point.", "4")

Do

HotKeySet($ks1, "GetPoints")

    If $number = $points Then
  PixGetTest()
    Endif
    

Until $exit = 1;

EndFunc

;====================PixSearch Related==========================

Func Searchit()

SoundPlay ( "C:\WINDOWS\Media\Windows XP Balloon.wav");

HotKeySet($ks1)
HotKeySet($ks2)

$pos = MouseGetPos()
$color = PixelGetColor ( $pos[0] , $pos[1] )
$leftcoord = $pos[0] - $spreadx
$topcoord = $pos[1] - $spready
$rightcoord = $pos[0] + $spreadx
$bottomcoord = $pos[1] + $spready

PixelSearch( $leftcoord , $topcoord , $rightcoord , $bottomcoord , $color , $shadevariation , $step )
    
    If @error = 0 Then
  $comment1 = InputBox("PixelSearch Input", "Enter a Comment for what this relates to.", "")
  FileWrite($file, "If PixelSearch(" & $leftcoord & "," & $topcoord & "," & $rightcoord & "," & $bottomcoord & "," & $color & "," & $shadevariation & "," & $step & ") Then")
  FileClose ( $file )
  $file = FileOpen("autopix.txt", 0)
  $output1 = FileReadLine ( $file , 1 )
  FileClose ( $file )
  ClipPut ( $output1 & Chr ( 59 ) & " " & $comment1 )
  MsgBox ( 0 , "Found", "PixelSearch Successful. Resultant Code sent to Clipboard.")
    Else
  MsgBox ( 0 , "Failure", "PixelSearch Failed.")
    Endif

$exit = 1;

EndFunc

;========================PixColor Related========================

Func GetPoints()

$number = $number + 1;
$pos = MouseGetPos()
$color = PixelGetColor ( $pos[0], $pos[1] )
Global $setit1 = $pos[0]
Global $setit2 = $pos[1]
Global $setit3 = $color

    If $points = $number Then
  FileWrite($file, "PixelGetColor(" & $setit1 & "," & $setit2 & ") = " & $setit3 & " Then")
    ElseIf $points > $number AND $number > 1 Then
  FileWrite($file, "PixelGetColor(" & $setit1 & "," & $setit2 & ") = " & $setit3 & " AND ")
    ElseIf $number = 1 Then
  FileWrite($file, "If PixelGetColor(" & $setit1 & "," & $setit2 & ") = " & $setit3 & " AND ")
    Endif

SoundPlay ( "C:\WINDOWS\Media\Windows XP Balloon.wav");

EndFunc

Func PixGetTest()

FileClose ( $file )
$file = FileOpen("autopix.txt", 0)


$output = FileReadLine ( $file , 1 )
     
  If $output Then
     $comment = InputBox("PixelGet Input", "Enter a Comment for what this relates to.", "")
     FileClose ( $file )
     ClipPut ( $output & Chr ( 59 ) & " " & $comment )
     MsgBox ( 0 , "Found", "PixelGetColor Successful. Resultant Code sent to Clipboard.")
     $number = 0;
  Else
     MsgBox ( 0 , "Failure", "PixelGet Failed.")
  Endif
     
$exit = 1;

EndFunc

;========================FrontEnd Loop==============================

Func Main()
    
    
    If $exit = 1 Then
  Global $continue = MsgBox ( 4 , "Instruction", "PixelSearch: Press ALT + 1. PixelGetColor: Press ALT + 2." & @CRLF & "Continue?")
  HotKeySet($ks1, "PixSearch")
  HotKeySet($ks2, "PixColor")
    Endif
    
    If $continue = 6 Then
  $continue = 0;
  $exit = 0;
    ElseIf $continue = 7 Then
  Cleanup()
    Endif

EndFunc

;=======================CleanUP TXT===============================

Func Cleanup()

FileDelete ( "autopix.txt" )
$loopit = 0;

EndFunc

Share this post


Link to post
Share on other sites

I took screenshots with fraps at 1280x1024 resolution and then set my destop resolution so i could correctly view them and got the coordinates and pixel color. The script works fine when I test it on the screenshots but when I actually get in the game it doesnt work. Any ideas why it might not be working as I am pretty sure I have coordinates and color right.

Share this post


Link to post
Share on other sites

set up a hot key to take the color of the coords you seek, then test them out to see if they are correct.

example:

hotkeyset("{pause}","getcolor"); Pause key
hotkeyset("!{pause}","showbox"); alt+Pause
while 1
sleep(100)
wend

func getcolor()
filewriteline("mytempfile.txt",PixelGetColor ( 100 , 300 ));example coords
endfunc

func showbox(); makes a small X float at that spot in most applications.
tooltip("X",100 , 300)
sleep(1000)
tooltip("")
endfun

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Try setting the pic as your desktop wallpaper and take the color from that. I found a couple times that if you are using Paint autoit reports a different color than when it is set to your desktop by 1 shade step or so for some reason *shrug* and the desktop colors worked correctly, for me at least. This could be the problem. No idea why this is and it is not a constant thing, the only times i have seen it happen is with a red shade, no idea if this matters. But try that and see if it fixes your problem.

Share this post


Link to post
Share on other sites

For anyone who plays ffxi I am trying to make a script that will play a sound when a GM msg's you. So far as ive told everyone I have it working in the screenshot but not in the game. If anyone would like to help me out let me know and I will send the the GM text screenshots. I want it for 1280x1024 overlay resolution and 1024x1024 backround resolution.

Share this post


Link to post
Share on other sites

to check the position, and if you have a cursor in the game, find the color of the cursor, and the spot you want. have autoit set to soundplay when you pass over it, and you can check your spot that way perhapse.

anyway just a thought for ya.


AutoIt3, the MACGYVER Pocket Knife for computers.

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