Sign in to follow this  
Followers 0

PixelSearch SplashScreen (PixelChecksum)

6 posts in this topic

#1 ·  Posted (edited)

Inspired by a misinterpretation of the request in this post during the wee hours of the morning:, I made this tool to help write PixelSearch and PixelChecksum lines for a script that you are writing. It creates a semi-transparent splash screen that you can move and resize to represent the area that you want to search. It was not intended to add a splash screen to a script that is actively searching for a pixel. Although you might be able to have a splash screen turn on and off right before each PixelSearch line as sort of a debug tool. You could also toggle this "feature" off and on via a hotkey... just in case you could not remember the area where you were searching... or if you are wondering if something has changed/moved in the app you are working with.

As with another of my scripts in the forum:

I have more comment lines than lines of AutoIt3 code.

Caveat: I'm not a gamer and I don't know if the way the script writes the PixelSearch line of code for you is the best for gaming. My hope is that this script might be of some use to those scripting for apps like Firefox and the like when you might want to check a pixel on the tool bar to see if a page has finished loading. I've tested it on apps like that - on just a toolbar icon or system tray icon.

For those really new to the forum...

Copy/paste the code below or download attached file at end of this post:

;blame herewasplato for this long winded script
;the script is for use with (Windows 2000/XP or later)

;the end result of running this script should be
;a PixelSearch line of code in the windows clipboard
;that you can paste into your script

; 1) Read all of the comments in this script

; 2) Run this script

; 3) Reposition/Resize the semi-transparent
;   splash screen to cover the area to be
;   searched by PixelSearch in your script

; 4) Press ESC

; 5) Move the mouse to the window and pixel
;   that you are searching for in your script

; 6) Press ESC

; 7) Paste the contents of the Windows clipboard
;   into your script

;more boring details:
;running the script should move the active window
;to position 0,0 on the desktop and a create a
;splash screen starting in that same 0,0 location

;the splash screen represents the size of the
;PixelSearch area

;if you must, you can change the
;transparency of the splash screen here:
$transparency = 100;A number in the range 0 - 255.
;The larger the number,
;the more transparent the window will become.
;hopefully you can find a transparency setting that
;will allow you to see allow of the info behind
;the splash screen

;move the splash screen (PixelSearch area)
;via the left/right/up/down arrow keys
;(faster = shift-left/right/up/down)
;to the area of interest to you

;control the size of the splash screen (PixelSearch area)
;via the control-left/right/up/down arrow keys
;(faster = control-shift-left/right/up/down)

;PixelSearchs over large areas take CPU time
;so use the smallest search area possible

;if you make a large splash screen (PixelSearch area)
;it may flicker - you might control some of that by
;slowing down the splash screen "refresh rate" here:
$RefreshRate = 200

;read the help file on each of these settings
AutoItSetOption("PixelCoordMode", 0);do not change*
AutoItSetOption("MouseCoordMode", 0);do not change*
AutoItSetOption("WinTitleMatchMode", 3)
AutoItSetOption("TrayIconDebug", 1)
;see the very bottom of the script for more info

;a lazy way to prevent two copies of this script
;from running at the same time
$S_running = "pix-splash-window"
If WinExists($S_running) Then
    MsgBox(0, "AutoIt", "This script is already running")

;gives you a chance to make the window
;of interest active before the script
;moves the active window to 0,0
MsgBox(0, "AutoIt PixelSearch Tool", _
        "You have 10 seconds to make the " & _
        "window of interest Active.", 10)

;sets the splash screen's starting size and position
$left = 0;leave
$top = 0;leave
$right = 100;change the starting size if you wish
$bottom = 100;change the starting size if you wish
$Xoffset = 0;leave
$Yoffset = 0;leave

;sets the hotkeys
HotKeySet("{ESC}", "ExitEachLoop")

;moves the splash screen
HotKeySet("{RIGHT}", "Xoffset_up")
HotKeySet("{DOWN}", "Yoffset_up")
HotKeySet("{LEFT}", "Xoffset_down")
HotKeySet("{UP}", "Yoffset_down")

;moves the splash screen in larger increments
HotKeySet("+{RIGHT}", "Xoffset_upL")
HotKeySet("+{DOWN}", "Yoffset_upL")
HotKeySet("+{LEFT}", "Xoffset_downL")
HotKeySet("+{UP}", "Yoffset_downL")

;resizes the splash screen
HotKeySet("^{RIGHT}", "right_up")
HotKeySet("^{DOWN}", "bottom_up")
HotKeySet("^{LEFT}", "right_down")
HotKeySet("^{UP}", "bottom_down")

;resizes the splash screen in larger increments
HotKeySet("^+{RIGHT}", "right_upL")
HotKeySet("^+{DOWN}", "bottom_upL")
HotKeySet("^+{LEFT}", "right_downL")
HotKeySet("^+{UP}", "bottom_downL")

;gets the mouse cursor out of the way
$OriginalMousePosition = MouseGetPos()
$DW = @DesktopWidth;make small for post width
$DH = @DesktopHeight;make small for post width
MouseMove($DW, $DH, 0)

;moves the active window to 0,0
WinMove("", "", 0, 0)

;this loop allows you to Reposition/Resize
;the splash screen to cover the area of interest
$ExitEachLoop = "no"
While 1
    SplashTextOn("PixArea", "", _
            $right - $left, _
            $bottom - $top, _
            $left + $Xoffset, _
            $top + $Yoffset, 1 + 16)
    WinSetTrans("PixArea", "", $transparency)
    If $ExitEachLoop = "yes" Then ExitLoop

;save the location/size info of the area
;to search via PixelSearch
$part1 = '$PScoord = PixelSearch(' & _
        $left + $Xoffset & ',' & _
        $top + $Yoffset & ',' & _
        $right + $Xoffset & ',' & _
        $bottom + $Yoffset & ','

;puts the mouse back where it was
MouseMove($OriginalMousePosition[0], _
        $OriginalMousePosition[1], 0)

;this loop allows you to position the mouse over the
;pixel that has the color that you are interested in
;searching for in your script
$ExitEachLoop = "no"
While 1
    $pos = MouseGetPos()
    $part2 = PixelGetColor($pos[0], $pos[1])
    If $ExitEachLoop = "yes" Then ExitLoop

;creates the line of code for your script
ClipPut($part1 & $part2 & ')')

Func ExitEachLoop()
    $ExitEachLoop = "yes"

Func Xoffset_up()
    If ($right + $Xoffset) < $DW Then $Xoffset = $Xoffset + 1

Func Yoffset_up()
    If ($bottom + $Yoffset) < $DH Then $Yoffset = $Yoffset + 1

Func Xoffset_down()
    If $Xoffset > 0 Then $Xoffset = $Xoffset - 1

Func Yoffset_down()
    If $Yoffset > 0 Then $Yoffset = $Yoffset - 1

;moves in larger increments
Func Xoffset_upL()
    If ($right + $Xoffset) < $DW Then $Xoffset = $Xoffset + 10

Func Yoffset_upL()
    If ($bottom + $Yoffset) < $DH Then $Yoffset = $Yoffset + 10

Func Xoffset_downL()
    If $Xoffset > 0 Then $Xoffset = $Xoffset - 10

Func Yoffset_downL()
    If $Yoffset > 0 Then $Yoffset = $Yoffset - 10

Func right_up()
    If ($right - $left + $Xoffset) < $DW Then $right = $right + 1

Func bottom_up()
    If ($bottom - $top + $Yoffset) < $DH Then $bottom = $bottom + 1

Func right_down()
    If $right > 0 Then $right = $right - 1

Func bottom_down()
    If $bottom > 0 Then $bottom = $bottom - 1

;resize in larger increments
Func right_upL()
    If ($right - $left + $Xoffset) < $DW Then $right = $right + 10

Func bottom_upL()
    If ($bottom - $top + $Yoffset) < $DH Then $bottom = $bottom + 10

Func right_downL()
    If $right > 0 Then $right = $right - 10

Func bottom_downL()
    If $bottom > 0 Then $bottom = $bottom - 10

;;;;;;;;;;;start test script;;;;;;;;;;;;;;
;you can test the output of the script above
;with a small test script like this:
AutoItSetOption("PixelCoordMode", 0)
AutoItSetOption("MouseCoordMode", 0)

;just paste over the line below
;with the output of the script above
$PScoord = PixelSearch(0, 0, 10, 10, 8650752);*
;*consult help file for shades and steps

If IsArray($PScoord) Then
    MouseMove($PScoord[0], $PScoord[1])
    MsgBox(0, "AutoIt", "Error")
;;;;;;;;;;;end test script;;;;;;;;;;;;;;

;more info for your script:
;take a look at the help file to learn
;about these two settings
AutoItSetOption("PixelCoordMode", 0)
AutoItSetOption("MouseCoordMode", 0)
;you can/should put them near the top of your script
;you can change the "0" to a "1" BUT...
;you will probably want to do so for both lines
;if you are going to use mouse clicks

;your script does not have to position
;the window that you are searching at 0,0

corrected typos,

changed some text,

uploaded slight changes... changes in functionality - I hope :-)


Added msgbox that will go away after 10 seconds...


Changed to AutoIt tags instead of code tags


Edited by herewasplato


Share this post

Link to post
Share on other sites

This should come in handy some how or other good job :P

Once my friend told me that he had found Jesus. I thought to myself, "Woohoo, we're rich!" It turns out he meant something different.Sometimes I just like to lay in my bed and look up at the stars and wonder..where the hell did my roof go?

Share this post

Link to post
Share on other sites

This should come in handy some how or other good job :P

Good; then it was't a total waste of my time.....


Share this post

Link to post
Share on other sites

#4 ·  Posted (edited)

text removed by JoseEdwin... sorry green.

Edited by joseedwin

Share this post

Link to post
Share on other sites

#5 ·  Posted (edited)

Edit - he fixed his post, so I'll fix mine.

Back on topic (so I don't break my own rule), plato you made this whole thing for a help request? That's so.. above the standard of help. Lots of detail in there. Nice.

Edited by greenmachine

Share this post

Link to post
Share on other sites

...plato you made this whole thing for a help request? That's so.. above the standard of help. Lots of detail in there. Nice.

Thanks. It was just one of those holiday things with lots of time to repy to that post. I kinda wished the OP had needed it - since I don't.

Most of the inquiries that I've had about it seem to think that they are supposed to add all or part of the tool's code to the script that they are writing.

So, just to repeat for the newbies:

You run the tool

The tool writes to the Windows clipboard

You paste the clipboard's contents into the script that you are writing.


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