Sign in to follow this  
Followers 0
DarkKitty7

Need assistance with script

6 posts in this topic

Hello I can't seem to figure the last part of my script out so i'm posting here for possible help.

I'd like for when i turn it on, it scans the "2182, 437" area of my desktop here for the "16316667" color, when the color changes i want it to play the "music.wav" 3 times, and then wait for "16316667" to re-appear, once the color "16316667" has re-appeared then I'd like for it to start all over at the top, and wait until "16316667" has dissappeared.

Currently the error is: it seems to be stuck in an infinite loop of spamming 'music.wav' once the pixel changes and then it keeps repeating and not stopping, i'd like for it to stop until color "16316667" comes back.

Hope that makes sense, thanks =)

Global $on=0
HotKeySet("{a}", "Music")
While 1
Sleep(1000)
WEnd


Func Music()
if $on=0 Then
SoundPlay("H:\Music.wav"); On
$on=1
Sleep(200)

Else

Beep(5500, 500) ; Off
$on=0
Sleep(500)
EndIf
While $on=1
Sleep(1000)
PixelSearch(2182, 437, 2182, 437, 16316667, 10) ;music
If @error Then
SoundPlay("H:\Music.wav")
Sleep(10000)
SoundPlay("H:\Music.wav")
Sleep(10000)
SoundPlay("H:\Music.wav")
Else
PixelSearch(2182, 437, 2182, 437, 16316667, 10)
If Not @error Then
EndIf
EndIf
WEnd
EndFunc

Share this post


Link to post
Share on other sites



What application are you trying to automate? Maybe there is a better way than that.

Hi!


My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Share this post


Link to post
Share on other sites

It's not an application its just a pixel of color on my desktop

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Check if it works

#include <WinAPI.au3>
Global $fContinueLoop = False
Global $hDesktop = _WinAPI_GetDesktopWindow()

HotKeySet("{a}", "Music")
HotKeySet("{x}", "ToggleMusicLoop") ;For Exitting the Loop
While 1
Sleep(10) ;Shouldn't be more than 10
WEnd


Func Music()

While $fContinueLoop ;Continue until X is pressed
Sleep(10)
PixelSearch(2182, 437, 2182, 437, 16316667, 10, 1, $hDesktop) ;Search the Desktop Window
If @error Then ;Color Changed
For $i = 0 To 3 ;Play the Song Thrice
SoundPlay("H:\Music.wav")
Sleep(10000)
Next
EndIf
;Lets wait for the color to reappear
PixelWait(2182, 437, 2182, 437, 16316667, 10, 1, $hDesktop) ;Search the Desktop Window
WEnd

EndFunc   ;==>Music

Func ToggleMusicLoop()
$fContinueLoop = Not $fContinueLoop
EndFunc   ;==>ToggleMusicLoop

Func PixelWait($left, $top, $right, $bottom, $color, $shadevariation = 0, $step = 1, $hwnd = 0, $iTimeout = 5000) ;$iTimeout - Wait for 5Secs, set this to 0 to wait forever
Local $iTimer = 0, $aRet = 0
If $iTimeout Then $iTimer = TimerInit()

Do
If $iTimeout And TimerDiff($iTimer) > $iTimeout Then Return SetError(1, 0, 0)
$aRet = PixelSearch($left, $top, $right, $bottom, $color, $shadevariation, $step, $hwnd) ;Search
Until (@error = 0)

Return $aRet
EndFunc   ;==>PixelWait
Regards :) Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

this one does not work for me, and to be honest is quite confusing as well, i wanted to keep the code very simple like my above example since i'm just starting to get into autoit.

i think i need to setup some type of variables, can autoit only do $example=0 and $example=1 ? or can you add more like =2 =3 =4?

Share this post


Link to post
Share on other sites

Does this help

Global $fContinueLoop = False

HotKeySet("{a}", "Music")
HotKeySet("{x}", "ToggleMusicLoop") ;For Exitting the Loop
While 1
Sleep(10)
WEnd


Func Music()
$fContinueLoop = True ;So that the loop runs
While $fContinueLoop

Sleep(10)

PixelSearch(2182, 437, 2182, 437, 16316667, 10) ;Search the Pixel

If @error Then ;Color Changed
SoundPlay("H:\Music.wav")
Sleep(10000)
SoundPlay("H:\Music.wav")
Sleep(10000)
SoundPlay("H:\Music.wav")
Sleep(10000)

;Lets wait for the color to reappear
Do ;Now search the pixel until it is found
PixelSearch(2182, 437, 2182, 437, 16316667, 10) ;Search the Pixel
Until @error = 0 ;if no error then pixel is found

EndIf

WEnd

EndFunc   ;==>Music

Func ToggleMusicLoop()
$fContinueLoop = False
;if the loop inside function Music is running it would end since $fContinueloop is now set to false
EndFunc   ;==>ToggleMusicLoop
Ask if you have any problems with this script. In AutoIt variables can hold char, numbers and many other. So you can make $i = 2

Regards :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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