Jump to content
Sign in to follow this  
Drew

PixelSearch Isn't working Correctly.

Recommended Posts

Drew

Me doing this wrong is always an option however:

Through various testing I don't understand wtf is going on here.

I have MsPaint open and no matter what color I test with , the array containing the coords is ALWAYS off on the Y axis.

It is lined up on the X-axis to the first correct pixel , left to right , but on the Y-axis its always about 40 pixels too low.

Here's an example of one of the tests I ran...

I was trying to find and click a pure Yellow pixel in this example.... The little red square is where it clicked after I ran the function. ( I will provide the code on down. )

http://img292.imageshack.us/my.php?image=testingpr2.png

Image wasn't working on my end , so heres the link: http://img292.imageshack.us/my.php?image=testingpr2.png

Here's the very simple function I'm using trying to figure out WTF is wrong , because pixelsearch wasn't working right in my current project:

Func _Paint()
    Opt("MouseCoordMode", 2)
    $pixelsearch = PixelSearch( 215, 80, 373, 204, 0xFFFF00)
    MouseClick("left", $pixelsearch[0], $pixelsearch[1])
EndFunc

Any insight?

Edited by Drew

Share this post


Link to post
Share on other sites
dgarrett8

Have you ever got pixelsearch to work for you before? curious


"I think, therefore I am"[size="1"]René Descartes[/size]

Share this post


Link to post
Share on other sites
dgarrett8

I would agree with Alex.


"I think, therefore I am"[size="1"]René Descartes[/size]

Share this post


Link to post
Share on other sites
Drew

But the mousecoord option lets me use the coordinates of the client area of the window I thought.

I need that because the window won't always be in the same position. =/. I'll try it for the sake of the MsPaint test however.

Share this post


Link to post
Share on other sites
AdmiralAlkex

But the mousecoord option lets me use the coordinates of the client area of the window I thought.

I need that because the window won't always be in the same position. =/. I'll try it for the sake of the MsPaint test however.

Changing MouseCoordMode will only change settings for mouse related stuff like MouseClick(), MouseMove() etc, not for PixelSearch and that's why it did't move to the right coordinates on your previous test (there isn't any automatical conversion)

One way to fix this is to remove MouseCoordMode and use _WinAPI_ScreenToClient() to convert the returned positions from PixelSearch, and then use that for the MouseClick().

Share this post


Link to post
Share on other sites
Drew

Alright so whats the best way to go about getting pixelsearch to work within the client area of a certain window?

I have some ideas , but they have some blanks in em if you have any advice.

Share this post


Link to post
Share on other sites
Drew

Alright since PixelSearch works based upon Screen coordinates , and not Client coordinates....

I'm working on a way to GET the client coordinates using the Screen coordinates based upon the active windows position.

The Client window I'm getting pixelsearch coordinates for will ALWAYS be 800x600.

$Pos = WinGetPos("[active]")
    $Xleft = $pos[0]
    $XTop = $pos[1]
    $Right = $pos[0] + 800
    $Bottom = $pos[1] + 600
    $MidPointX = $pos[0] + 400
    $MidPointY = $pos[1] + 300
    
;Bottom Left Pixel Search
    
    $BLeft = $MidPointX
    $BTop = $MidPointY
    $BRight = $MidPointX + 200
    $BBottom = $MidPointY + 150

The top set ( before the ;Bottom Left ) should give me the left, top, right , and bottom coords that I could use to search the entire window for the given Pixel.

The bottom set ( after the ;Bottom Left ) is going to be used ONLY to search the bottom right 1/4 of the window.

I'm in need of a second opinion to make sure I did the math and all right. Anybody?

EDIT!!!

Rofl. I just noticed it says Bottom Left several times when referring to the last 4 variable declarations , is supposed to mean Bottom Right.

Edited by Drew

Share this post


Link to post
Share on other sites
Leopardfist

Your making that much much harder than it has to be. Simplicity is your friend.

Example of using client coordinates for pixelsearch:

Func _Paint()
    Opt("MouseCoordMode", 2)
    Opt("Pixelcoordmode", 2)
    $pixelsearch = PixelSearch( 215, 80, 373, 204, 0xFFFF00)
    MouseClick("left", $pixelsearch[0], $pixelsearch[1])
EndFunc

And if pixelcoordmode does not work with pixelsearch, you can do the following mathematical algorithm to deduce the needed coords:

Opt("Mousecoordmode", 2)
Mousemove(215, 80)
Opt("Mousecoordmode", 1)
Local $Ptr[2] = MouseGetPos()
Local $OffsetX = $Ptr[0] - 215
Local $OffsetY = $Ptr[1] - 80  ;this is your offset from screen to client!
Opt("Mousecoordmode", 2)
Local $TopLeftX = 215 + $OffsetX
Local $TopleftY = 80 + $OffsetY
Local $BottomRightX = 373 + $OffsetX
Local $BottomRightY = 204 + $OffsetY
Local $pixelsearch = PixelSearch( $TopleftX, $TopleftY, $BottomrightX, $BottomrightY, 0xFFFF00)
MouseClick("left", $pixelsearch[0] + $OffsetX, $pixelsearch[1] + $OffsetY)

One of those should solve your problem! And it does not matter where the window is moved, as long as the target coord is not off screen.

EDIT: You MIGHT have to change this to get it to work right. I am to tired to think clearly and it might need to be changed from - to +

Local $OffsetX = $Ptr[0] - 215
Local $OffsetY = $Ptr[1] - 80  ;this is your offset from screen to client!

If it does not work, change the -215 and -80 to +215 and + 80.

Edited by Leopardfist

Share this post


Link to post
Share on other sites
Leopardfist

$Pos = WinGetPos("[active]")

$Xleft = $pos[0]

$XTop = $pos[1]

$Right = $pos[0] + 800

$Bottom = $pos[1] + 600

$MidPointX = $pos[0] + 400

$MidPointY = $pos[1] + 300

;Bottom Left Pixel Search

$BLeft = $MidPointX

$BTop = $MidPointY

$BRight = $MidPointX + 200

$BBottom = $MidPointY + 150

Drew, that won't work because it does not take into account the window border and title bar. Your pixels will be off by those amounts.

Share this post


Link to post
Share on other sites
Drew

Actually it works great. Countering the 10-15 pixel difference from the title was nothing , and the border flaw serves no problem.

Thank you for your help though :).

Share this post


Link to post
Share on other sites
Leopardfist

Actually it works great. Countering the 10-15 pixel difference from the title was nothing , and the border flaw serves no problem.

I agree, if you KNOW the border dimensions this is great, but if he wants this to work across several platforms for other people, you cannot know those dimensions. I went thru this with a program I wrote. Of course you can go into more complicated DLL stuff to get that info, but the little Offset code I did works just as good. I could of swore thought that Opt("PixelCoordMode", 2) included pixelsearch function. Are you sure it doesn't? He did not include that in his first script.

EDIT: Nevermind LOL, I just noticed YOU are the original poster who inquired about this, I was thiking you were trying to help someone else. If what you ended up with works, great.

Edited by Leopardfist

Share this post


Link to post
Share on other sites
Drew

Lol :lmao:

Thank you for taking your time to try and help :).

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.