Jump to content

Pixelsearch & annoying coordinates


Recommended Posts

Hai out there

i've been working with Pixelsearch for a while, but after some time it gets annoying to always write 4 different coordinates in.

Is there a way to get the positions of a window by, for an example, WinGetPos?

Example, note that this one doesn't work ;)

$Window = WinGetPos("MyWindow")
while 3
$coor = PixelSearch( $Window[0], $Window[1], $Window[2], $Window[3], 0x0000FF, 2, 2 )
While @error = 0
Mouseclick("LEFT",$coor[0],$coor[1])
$coor = PixelSearch( $Window[0], $Window[1], $Window[2], $Window[3], 0x0000FF, 2, 2 )
Wend
Wend

any help would be appreciated :blink:

Edited by Tyranlol
[u]Only by Attempting the Impossible You Can Earn the Remarkable[/u]
Link to comment
Share on other sites

Make your own function.

If you want to get co-ordinates of the window each time, use something like this.

Func _PixelSearchWindow($sTitle, $sText, $Colour, $iShade = "", $iStep = "")
    local $aPos = WinGetPos($sTitle, $sText)
    If Not IsArray($aPos) Then Return SetError(2, 0, -1)
    Return PixelSearch($aPos[0], $aPos[1], $aPos[0]+$aPos[2], $aPos[1]+$aPos[3], $Colour, $iShade, $iStep)
EndFunc

If you want to use the same array of co-ordinates returned by a WinGetPos, use something like this.

Func _PixelSearchByArray($aPos, $Colour, $iShade = "", $iStep = "")
    If Not IsArray($aPos) Then Return SetError(2, 0, -1)
    Return PixelSearch($aPos[0], $aPos[1], $aPos[0]+$aPos[2], $aPos[1]+$aPos[3], $Colour, $iShade, $iStep)
EndFunc

Edit: note not tested the code on anything

Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Make your own function.

If you want to get co-ordinates of the window each time, use something like this.

Func _PixelSearchWindow($sTitle, $sText, $Colour, $iShade = "", $iStep = "")
    local $aPos = WinGetPos($sTitle, $sText)
    If Not IsArray($aPos) Then Return SetError(2, 0, -1)
    Return PixelSearch($aPos[0], $aPos[1], $aPos[0]+$aPos[2], $aPos[1]+$aPos[3], $Colour, $iShade, $iStep)
EndFunc

If you want to use the same array of co-ordinates returned by a WinGetPos, use something like this.

Func _PixelSearchByArray($aPos, $Colour, $iShade = "", $iStep = "")
    If Not IsArray($aPos) Then Return SetError(2, 0, -1)
    Return PixelSearch($aPos[0], $aPos[1], $aPos[0]+$aPos[2], $aPos[1]+$aPos[3], $Colour, $iShade, $iStep)
EndFunc

Edit: note not tested the code on anything

Thanks for the reply Yoriz.

i'll take a look when i get home :blink:

[u]Only by Attempting the Impossible You Can Earn the Remarkable[/u]
Link to comment
Share on other sites

Does this example make sense ?

$sTitle = "Untitled - Notepad"
Run("NotePad")
WinWait($sTitle)
$aPos = _PixelSearchWindow($sTitle, "", 0xFFFFFF)
If IsArray($aPos) Then MouseMove($aPos[0], $aPos[1])
_ArrayDisplay($aPos, "White Found")
WinClose($sTitle)
WinWaitClose($sTitle)

Run("NotePad")
WinWait($sTitle)
$aWinPos = WinGetPos($sTitle, "")
$aPos = _PixelSearchByArray($aWinPos, 0xFFFFFF)
If IsArray($aPos) Then MouseMove($aPos[0], $aPos[1])
_ArrayDisplay($aPos, "White Found")
WinActivate($sTitle)
$aPos = _PixelSearchByArray($aWinPos, 0x000000)
If IsArray($aPos) Then MouseMove($aPos[0], $aPos[1])
_ArrayDisplay($aPos, "Black Found")
WinClose($sTitle)

Func _PixelSearchWindow($sTitle, $sText, $Colour, $iShade = "", $iStep = "")
    Local $aPos = WinGetPos($sTitle, $sText)
    If Not IsArray($aPos) Then Return SetError(2, 0, -1)
    Return PixelSearch($aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3], $Colour, $iShade, $iStep)
EndFunc   ;==>_PixelSearchWindow

Func _PixelSearchByArray($aPos, $Colour, $iShade = "", $iStep = "")
    If Not IsArray($aPos) Then Return SetError(2, 0, -1)
    Return PixelSearch($aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3], $Colour, $iShade, $iStep)
EndFunc   ;==>_PixelSearchByArray
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Does this example make sense ?

$sTitle = "Untitled - Notepad"
Run("NotePad")
WinWait($sTitle)
$aPos = _PixelSearchWindow($sTitle, "", 0xFFFFFF)
If IsArray($aPos) Then MouseMove($aPos[0], $aPos[1])
_ArrayDisplay($aPos, "White Found")
WinClose($sTitle)
WinWaitClose($sTitle)

Run("NotePad")
WinWait($sTitle)
$aWinPos = WinGetPos($sTitle, "")
$aPos = _PixelSearchByArray($aWinPos, 0xFFFFFF)
If IsArray($aPos) Then MouseMove($aPos[0], $aPos[1])
_ArrayDisplay($aPos, "White Found")
WinActivate($sTitle)
$aPos = _PixelSearchByArray($aWinPos, 0x000000)
If IsArray($aPos) Then MouseMove($aPos[0], $aPos[1])
_ArrayDisplay($aPos, "Black Found")
WinClose($sTitle)

Func _PixelSearchWindow($sTitle, $sText, $Colour, $iShade = "", $iStep = "")
    Local $aPos = WinGetPos($sTitle, $sText)
    If Not IsArray($aPos) Then Return SetError(2, 0, -1)
    Return PixelSearch($aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3], $Colour, $iShade, $iStep)
EndFunc   ;==>_PixelSearchWindow

Func _PixelSearchByArray($aPos, $Colour, $iShade = "", $iStep = "")
    If Not IsArray($aPos) Then Return SetError(2, 0, -1)
    Return PixelSearch($aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3], $Colour, $iShade, $iStep)
EndFunc   ;==>_PixelSearchByArray

I get the point yea. but are you trying to use a fuction called PixelSearchWindow ? because that one doesn't exist, i think that's why it keeps popping up with a error here
[u]Only by Attempting the Impossible You Can Earn the Remarkable[/u]
Link to comment
Share on other sites

:blink: The whole point im getting at is, if you find yourself repeating code entry you create your own function, _PixelSearchWindow is a function i created combining the internal functions WinGetPos & PixelSearch. The example is using self created functions, if you copy the whole lot it including the new functions it will work. ;)
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

:blink: The whole point im getting at is, if you find yourself repeating code entry you create your own function, _PixelSearchWindow is a function i created combining the internal functions WinGetPos & PixelSearch. The example is using self created functions, if you copy the whole lot it including the new functions it will work. ;)

Oh lol sorry, my fault. got it working now & mixed with my own code, thanks for the help buddy :P
[u]Only by Attempting the Impossible You Can Earn the Remarkable[/u]
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...