Jump to content

Help with a prioritizing pixel search?


Recommended Posts

Dim $ClickMouse, $MousePrimary, $MouseSecondary, $ExitKey
Dim $Color, $Left, $Top, $Right, $Bottom, $SearchResult, $CheckSwap
$CheckSwap = RegRead("HKEY_CURRENT_USERControl PanelMouse", "SwapMouseButtons")
If $CheckSwap = 1 Then
$MousePrimary = "right"
$MouseSecondary = "left"
Else
$MousePrimary = "left"
$MouseSecondary = "right"
EndIf
; ************************************************* ;
; Change your settings here ;
; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ;
$ExitKey = "{ESC}"
Local $colors[3] = [ 0x1CFC27, 0x4E221b, 0x8C96DE ]
$Left = 0
$Top = 0
$Right = 1675
$Bottom = 1006
$ClickMouse = $MousePrimary
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ;
; Change your settings here ;
; ************************************************* ;
HotKeySet($ExitKey, '_Exit')

While 1
For $i = 0 To 2
$c = PixelSearch($Left, $Top, $Right, $Bottom, $colors [$i])
If IsArray($c) Then
MouseClick($ClickMouse, $c[0], $c[1], 1, 0)
ExitLoop
EndIf
Next
WEnd
Func _Exit()
Exit
EndFunc
Hello all,

Great forums here - i've learned alot just browing around!

My question is - can I make a pixel search that prioritizes? Here is my script so far -

So basically, right now it has 3 colors it looks for, and when it finds one it clicks it a whole bunch. What I WANT to do, is somehow make it so that it is always looking for the first color as priority 1 - and if it sees it, it instantly clicks that one - and otherwise, it is looking for priority 2 - and instnatly clicks that one unless priority one is seen, and same goes for number 3, which is a color it will almost always see ( so there for the other ones never get clicked as they come into view because #3 is always in view.)

I hope I explained that well enough. Thank you for you for any advice or ideas!!!

-Shadow

Edited by shadowxdrago
Link to comment
Share on other sites

as written, your script does just as you want it to...what's the problem? By clicking number 3, does something occur that does not allow 1 or 2 to appear?

If anything, the only thing i would change is:

[color=#004040]For $i = 0 To UBound ( [color=#5A5A5A]$colors[/color] )[/color]-1

Edit: adjusted to include proper ubound

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thanks jdelaney. Would you mind explaining a little bit about what your suggestion will do? I'm pretty new to scripting. Thanks for the advice though.

So you are saying that the order in which I put the 3 hex codes for the pixel search is the order it will search for them automatically?

@scullion - i'm going to ignore your ignorant, unhelpful post. Take your trolling elsewhere, either pitch in to try and help me like a good little forum member, or keep to yourself. I never said the script doesn't "work" i'm trying to learn new things and become more skilled in what I am trying to do.

Link to comment
Share on other sites

If anything, the only thing i would change is:

For $i = 0 To UBound ($colors )

If you do that the script will exit with an error because the value of Ubound($Colors) is going to be 3, and there are only 3 elements in the array, so when it tries to read from the 4th element ($colors[3]), it will throw out a subscript error.

Also, if you know how large your array is already, using Ubound is just going to slow your script down unnecessarily.

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

Link to comment
Share on other sites

Whoops, good catch, updated my ubound...i always find dynamic better, so you only need to add additional colors, and not subsequent scripting that you need to search and destroy the hardcoded values...I suppose you can always make a variable set to the ubound()-1, and then that will update without having to recall the function multiple times...I'll wait for a moderator before helping out more, had my hand slapped before

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...