Jump to content

Move window according to PixelSearch coordinates or PixelSearch a particular window?


Recommended Posts

Hi,

I have a script that PixelSearches for a particular colour in a window. Every time this window opens it opens in a fairly random place on the screen, so I have to move it to the upper right hand side of the screen to ensure PixelSearch searches the right window.

The best solution to this would obviously be to tell PixelSearch to search in a particular window regardless of where it is... is this possible?

If the above isn't possible, then is there any way, when the script is started, for the window to get moved to the coordinates that are in the PixelSearch code?

Thanks,

Craig.

Link to comment
Share on other sites

  • Moderators

I believe the Beta has an Hwnd option (unless they took it out) :D

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I believe the Beta has an Hwnd option (unless they took it out) :D

Yes that option is in the beta versions. However, if it is a window that you move programmatically, then you obviously already know the window position, and you can provide these as arguments to PixelSearch. That should work just as well as using the window handle.

Link to comment
Share on other sites

  • Moderators

Yes that option is in the beta versions. However, if it is a window that you move programmatically, then you obviously already know the window position, and you can provide these as arguments to PixelSearch. That should work just as well as using the window handle.

Iterate that a bit... this would be using Opt("PixelCoordMode", 2) and getting the client coords of where you want to search versus the screen coords (Which I would assume would be the same for Hwnd anyway).

I like the option for hwnd (though I haven't used it yet, but based on other languages I have used the feature in) because if the window is partially covered, it will still get the colors if visible.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Any chance of some examples please? I'm fairly new to AutoIt.

Here's the simplest way to do it. Like SmOke_N mentioned, that will give you screen coordinates, so if you need them in window coordinates you'll need to shift the result.

$winTitle="Inbox - Microsoft Outlook"
$color=0xFF0000

$pos=WinGetPos($winTitle)
$array=PixelSearch($pos[0],$pos[1],$pos[0]+$pos[2]-1,$pos[1]+$pos[3]-1,$color)

If @error Then
    MsgBox(0,"","Not found")
Else
    MsgBox(0,"",$array[0]&","&$array[1])
EndIf
Edited by joshtp
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...