Jump to content

Pixelsearch hwnd


Recommended Posts

if i specify hwnd on the Pixelsearch does the script run only in the specify window, for example im using the script in a mozilla browser and i open a google chorome the script affect google chorome?

If not does the code will be running even thou i open a another browser?

and how to specify a hwnd when using a browser thanks im confuse. should i put title bar? class? window? or no.?

Edited by raijinlee
Link to comment
Share on other sites

  • 5 years later...

 

#include <MsgBoxConstants.au3> 

Local $iPID = Run("notepad.exe", "")


; Find a pure red pixel in the range 0,0-20,300
Local $aCoord = PixelSearch(0, 0, 20, 300, 0xFF0000)
If Not @error Then
    MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1])
EndIf

; Find a pure red pixel or a red pixel within 10 shades variations of pure red
$aCoord = PixelSearch(0, 0, 20, 300, 0xFF0000, 10)
If Not @error Then
    MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1])
EndIf
$hNotepad = WinGetHandle("Untitled - Notepad")

; Find a pure red pixel in the range 0,0-20,300
Local $aCoord = PixelSearch(0, 0, 20, 300, 0xFF0000)
If Not @error Then
    MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1],,,$hNotepad )
EndIf

; Find a pure red pixel or a red pixel within 10 shades variations of pure red
$aCoord = PixelSearch(0, 0, 20, 300, 0xFF0000, 10)
If Not @error Then
    MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1],,,$hNotepad )
EndIf
https://www.autoitscript.com/autoit3/docs/functions/PixelSearch.htm
https://www.autoitscript.com/autoit3/docs/functions/WinWait.htm
Link to comment
Share on other sites

On 5/18/2018 at 2:58 PM, chacoya121 said:

...., how does  pixelsearch hwnd work? ....

The "hwnd" parameter from the  PixelSearch() function in AutoIt help :-
"hwnd  - [optional] Window handle to be used. Default is the desktop window."

 I assumed this means that the pixel coordinates parameters are treated as if the "PixelCoordMode", Opt() function  uses relative,"0",  or, client area,"2" mode, and "hwnd" is the active window's handle.  The default "hwnd" parameter is treated as the default "PixelCoordMode" absolute mode, "1" - the desktop window.

Running:(3.3.14.5) on OS:WIN_10/  CPU:X64 OS:X64, I can not get the PixelSearch() function with the "hwnd" parameter (in the following example) to verify my above assumption.

I expected the first two PixelSearch() functions with no "hwnd" parameter not to work, which they didn't.
I expected the next two middle PixelSearch() functions  with the "hwnd" parameter to work, but they didn't.  (It appears the "hwnd" parameter is not working.)
I expected the last two PixelSearch() functions  under 'Opt("PixelCoordMode", 2)' to work, and they did work.  (a work-around)

In the example, a special case is where the red GUI is positioned close to the desktop's top left corner, coordinates (0, 0).   All six MsgBoxs activate because of the closeness of the values of the  relative, absolute, and client mode coordinates.
 

Local $iColor = 0xFF0000 ; <--- Change colour if existing colour on desktop is interferring with this script.

Local $hGUI = GUICreate("Example") ;, -1, -1, 0, -25) ;
GUISetBkColor($iColor, $hGUI)
Local $idBut = GUICtrlCreateButton("Exit", 310, 370, 85, 25)

; Display the GUI.
GUISetState(@SW_SHOW, $hGUI)
WinWaitActive($hGUI, "")

; --------------------- PixelSearch no hwnd parameter ------------------------
; Find a pure red pixel in the range (0,0) to (20,300) coordinates
Local $aCoord = PixelSearch(0, 0, 20, 300, $iColor)
If Not @error Then
    MsgBox(0, "", "No hwnd parameter, pure red pixel, X and Y are: " & $aCoord[0] & "," & $aCoord[1])
EndIf

; Find a pure red pixel or a red pixel within 10 shades variations of pure red
$aCoord = PixelSearch(0, 0, 20, 300, $iColor, 10)
If Not @error Then
    MsgBox(0, "", "No hwnd parameter, 10 shades variations, X and Y are: " & $aCoord[0] & "," & $aCoord[1])
EndIf

; --------------------- PixelSearch with hwnd parameter ------------------------
; PixelSearch ( left, top, right, bottom, color [, shade-variation = 0 [, step = 1 [, hwnd]]] )
Local $aCoord = PixelSearch(0, 0, 20, 300, $iColor, 0, 1, $hGUI)
If Not @error Then
    MsgBox(0, "", "Pure red X and Y are: " & $aCoord[0] & "," & $aCoord[1], $hGUI)
EndIf

; Find a pure red pixel or a red pixel within 10 shades variations of pure red
$aCoord = PixelSearch(0, 0, 20, 300, $iColor, 10, 1, $hGUI)
If Not @error Then
    MsgBox(0, "", "10 shades variations X and Y are: " & $aCoord[0] & "," & $aCoord[1], $hGUI)
EndIf

; ------------- Client pixel mode and no hwnd parameter -----------------------
Opt("PixelCoordMode", 2) ;1=absolute, 0=relative, 2=client

Local $aCoord = PixelSearch(0, 0, 20, 300, $iColor)
If Not @error Then
    MsgBox(0, "", "Client PixelCoordMode, pure red X and Y are: " & $aCoord[0] & "," & $aCoord[1], $hGUI)
EndIf

; Find a pure red pixel or a red pixel within 10 shades variations of pure red
$aCoord = PixelSearch(0, 0, 20, 300, $iColor, 10)
If Not @error Then
    MsgBox(0, "", "Client PixelCoordMode, 10 shades variations X and Y are: " & $aCoord[0] & "," & $aCoord[1], $hGUI)
EndIf

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case -3, $idBut
            ExitLoop

    EndSwitch
WEnd

 

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...