Fission102

Using PixelGetColor in a loop, getting stuck!

12 posts in this topic

#1 ·  Posted (edited)

Hi guys, new here! 

Never really programmed with this autoit before, so I tried using the help menu and some previous threads on the forum.

However I'm getting stuck, here's the basic code so far (It's not complete, because I need this part to work before I can continue on with the algorithm)

What I'm trying to do is make a loop to continually check the colors at the positions I declared as variables, then check the conditions in the if statements, once it activates one if or elseif statement i want it to completely restart at the top of the while loop. Sometimes it doesn't activate at all, or if it does example: black black color at the two positions as true the first time it works, but when it re-does the loop if it's black black = true again it just seems like it disables and doesn't re-activate the same condition previously. 

Here's the while loop code I have so far. 

WinActivate("Double")
Sleep(250)
;HotKeySet ("F6", "ExitProg")

;Func ExitProg()
    ;Exit 0


While 1
$initiate = PixelGetColor (765,167)
$initiate2 = PixelGetColor (474,165)
$prev = PixelGetColor (1388,292)
$prev2 = PixelGetColor (1341,290)
$white = 0xF5F5F5
$blk = 0x444444
$red = 0xC9302C
$green = 0x449D44

  If (($prev == $prev2 == $blk) And ($initiate == $white)) Then
    MouseClick("left", 510, 403)
    Sleep(250)
    MouseClick("left", 646,402)
    Sleep(250)
    MouseClick("left", 1649,537)
    Sleep(15000)
  ElseIf (($prev == $prev2 == $red) And ($initiate == $white)) Then
    MouseClick("left", 510, 403)
    Sleep(250)
    MouseClick("left", 646,402)
    Sleep(250)
    MouseClick("left", 699,535)
    Sleep(15000)
   Elseif (($prev == $red) And ($prev2 == $blk) And ($initiate == $white)) Then
    MouseClick("left", 510, 403)
    Sleep(250)
    MouseClick("left", 646,402)
    Sleep(250)
    MouseClick("left", 699,535)
    Sleep(15000)
   Elseif (($prev == $blk) And ($prev2 == $red) And ($initiate == $white)) Then
    MouseClick("left", 510, 403)
    Sleep(250)
    MouseClick("left", 646,402)
    Sleep(250)
    MouseClick("left", 1649,537)
    Sleep(15000)
  Elseif (($initiate2 == $white)Or ($initiate == $red)) Then
    ;MouseMove (765,167)
    Sleep (250)
  EndIf
WEnd

Basically there's a progress bar that's red and turns to white, I'm trying to get it to continually check a certain position, when it's white I want it to activate the if statements or if it's red it would re-set and check down the loop. 

I'm not sure haha any help would be appreciated!

Fission

Edited by Fission102
Code edit

Share this post


Link to post
Share on other sites



Found the issue, I guess the if statement for the string needed to be separated to the following 

 

If (($prev == $blk) And ($prev2 == $blk) And ($initiate == $white)) Then

Instead of 

If (($prev == $prev2 == $blk) And ($initiate == $white)) Then

 

Share this post


Link to post
Share on other sites

Im just curious, why comparing in case sensitive?


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

Im just curious, why comparing in case sensitive?

You're right, I could probably just use an equals sign instead of '==', but I was unsure about the hex color code haha so it was more just lack of experience. Haven't programmed for a couple years and the program I'm taking at university doesn't really require a lot of it. 

1 person likes this

Share this post


Link to post
Share on other sites

When using == it converts both sides of the comparison to strings, and this isn't always what you're going to want to compare against. Especially if you're mixing Hex and Decimal numbers.

0xA = 10 would work, but 0xA == 10 wouldn't

Just something to remember.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

When using == it converts both sides of the comparison to strings, and this isn't always what you're going to want to compare against. Especially if you're mixing Hex and Decimal numbers.

0xA = 10 would work, but 0xA == 10 wouldn't

Just something to remember.

Cool thanks! I got one question, is there a way I can declare a mouseclick position into a variable ie: $click1 = MouseClick("left", 510, 403) , but not actually calling it at that point and time, then in the code I can replace all the mouse clicks with the say, $click1, just to clean it up or for easy editing instead of replacing them one by one. Cause I'm currently on line 120 and it's sorta getting out of hand lol. 

edit: maybe make it global variable or something? 

Edited by Fission102
adding

Share this post


Link to post
Share on other sites

You store the X and Y position, and then call it at will:

$clickX = 510
$clickY = 403
MouseClick("left", $clickX, $clickY)

 


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

You store the X and Y position, and then call it at will:

$clickX = 510
$clickY = 403
MouseClick("left", $clickX, $clickY)

 

Ahh I thought I could set the entire mouseclick function to one variable then call it whenever. I'll see what I can do thanks!!

I do have one more question if that's alright with you, maybe someone can point me to the right direction. I want to be able to highlight a certain textbox (integers only) copy it, then remember the copied value and multiply the integer by a certain value followed by pasting back into the highlighted section. Is this possible? ie: highlight in a textbox of value 1.0, multiply it by 2.85 and then paste it back into a textbox which would equal 5.7.

Would seem pretty useful for future ideas :P 

Fission

Share this post


Link to post
Share on other sites

Ahh I thought I could set the entire mouseclick function to one variable then call it whenever.

You can, of sorts...

$_MouseClick1 = _MouseClick1

$_MouseClick1()

Func _MouseClick1()
    MouseClick("Primary", 0, 0)
EndFunc

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I do have one more question if that's alright with you, maybe someone can point me to the right direction. I want to be able to highlight a certain textbox (integers only) copy it, then remember the copied value and multiply the integer by a certain value followed by pasting back into the highlighted section. Is this possible? ie: highlight in a textbox of value 1.0, multiply it by 2.85 and then paste it back into a textbox which would equal 5.7.

Would seem pretty useful for future ideas :P 

Fission

Yes, check clipput and clipget and send and play with it. ;)


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

You can, of sorts...

$_MouseClick1 = _MouseClick1

$_MouseClick1()

Func _MouseClick1()
    MouseClick("Primary", 0, 0)
EndFunc

 

Gotcha! Thanks

Share this post


Link to post
Share on other sites

Yes, check clipput and clipget and send and play with it. ;)

Cool, I'll check it out, thanks!! :D

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