Jump to content

pixel search around clicked area


Recommended Posts

I had another topic but it got to long and confusing, so heres wat im up to, I have this code:

$color = _ _ _ _ _ _

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep ( 250 )
    If _IsPressed("04", $dll) Then
        $coord = PixelSearch( 0, 0, 1023, 651, $color, 10, 20)
        If IsArray($coord) = 1 Then
            MouseClick('right', $coord[0], $coord[1], 1, 0)
        EndIf
    EndIf
WEnd
DllClose($dll)

and I want the pixel search to be within 50 pixels of the clicked area but I cant figure it out, and Ive already tried MouseGetPos()

Any help is greatly appreciated!

THANKS

Link to comment
Share on other sites

  • Moderators

I've answered this question... MouseGetPos() after _IsPressed()... Do I need to write it for you?

Edit, so this topic doesn't get too "confusing" for you.

$color = 0xFF0000
While 1
    Sleep ( 250 )
    If _IsPressed("01", $dll) Then
        $aSearch = _PixToMouse(50, $color)
        If Not @error Then
            MouseClick('right', $aSearch[0], $aSearch[1], 1, 0)
        EndIf
    EndIf
WEnd

Func _PixToMouse($iVariant, $iColor, $iShade = 0, $iStep = 1)
    $OptPCM = Opt('PixelCoordMode', 2)
    $OptMCM = Opt('MouseCoordMode', 2)
    Local $aMpos = MouseGetPos(), $aPix
    If IsArray($aMpos) Then
        $aPix = PixelSearch($aMpos[0], $aMpos[1], $aMpos[0] + $iVariant, $aMpos[1] + $iVariant, $iShade, $iStep)
        Opt('PixelCoordMode', $OptPCM)
        Opt('MouseCoordMode', $OptMCM)
        If IsArray($aPix) Then
            Return $aPix
        EndIf
    EndIf
    Return SetError(1, 0, 0)
EndFunc
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

I've answered this question... MouseGetPos() after _IsPressed()... Do I need to write it for you?

Thats wat i tried and it didnt work, mayb i wrote it rong,

i had this:

$color = 0xA52C29

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep ( 250 )
    If _IsPressed("04", $dll) Then
        $pos = MouseGetPos()
        $coord = PixelSearch($pos[0]-50, $pos[1]-50,$color, 5, 2)
        If IsArray($coord) = 1 Then
            MouseClick('right', $coord[0], $coord[1], 1, 0)
        EndIf
    EndIf
WEnd
DllClose($dll)
Link to comment
Share on other sites

  • Moderators

Thats wat i tried and it didnt work, mayb i wrote it rong,

See my edit. 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

  • Moderators

alright, let me try this, ty so much for ur help smoke

If your trying to check 50 in every direction, you may want to try this one:
$color = 0xFF0000
While 1
    Sleep(10)
    If _IsPressed("04", $dll) Then
        $aSearch = _PixToMouse(50, $color)
        If Not @error Then
            MouseClick('right', $aSearch[0], $aSearch[1], 1, 0)
        EndIf
    EndIf
WEnd

Func _PixToMouse($iVariant, $iColor, $iShade = 0, $iStep = 1)
    $OptPCM = Opt('PixelCoordMode', 2)
    $OptMCM = Opt('MouseCoordMode', 2)
    Local $aMpos = MouseGetPos(), $aPix
    If IsArray($aMpos) Then
        $aPix = PixelSearch($aMpos[0] - $iVariant, $aMpos[1] - $iVariant, _
            $aMpos[0] + $iVariant, $aMpos[1] + $iVariant, $iShade, $iStep)
        Opt('PixelCoordMode', $OptPCM)
        Opt('MouseCoordMode', $OptMCM)
        If IsArray($aPix) Then
            Return $aPix
        EndIf
    EndIf
    Return SetError(1, 0, 0)
EndFunc
The other one only checks to the right of the click, this one checks left and right as well as top and down.

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

If your trying to check 50 in every direction, you may want to try this one:

$color = 0xFF0000
While 1
    Sleep(10)
    If _IsPressed("04", $dll) Then
        $aSearch = _PixToMouse(50, $color)
        If Not @error Then
            MouseClick('right', $aSearch[0], $aSearch[1], 1, 0)
        EndIf
    EndIf
WEnd

Func _PixToMouse($iVariant, $iColor, $iShade = 0, $iStep = 1)
    $OptPCM = Opt('PixelCoordMode', 2)
    $OptMCM = Opt('MouseCoordMode', 2)
    Local $aMpos = MouseGetPos(), $aPix
    If IsArray($aMpos) Then
        $aPix = PixelSearch($aMpos[0] - $iVariant, $aMpos[1] - $iVariant, _
            $aMpos[0] + $iVariant, $aMpos[1] + $iVariant, $iShade, $iStep)
        Opt('PixelCoordMode', $OptPCM)
        Opt('MouseCoordMode', $OptMCM)
        If IsArray($aPix) Then
            Return $aPix
        EndIf
    EndIf
    Return SetError(1, 0, 0)
EndFunc
The other one only checks to the right of the click, this one checks left and right as well as top and down.
Thanks smoke, but in both of them I get an error on this line:

If _IsPressed("04", $dll) Then

Which doesnt make since because I have the same line in the script I tried using and it worked, and yes, i do have the latest version, I downlaoded it yesterday

Link to comment
Share on other sites

  • Moderators

Does the error say: "wrong color underpants" ? Or something else?

Lar.

:P

Thanks smoke, but in both of them I get an error on this line:

If _IsPressed("04", $dll) Then

Which doesnt make since because I have the same line in the script I tried using and it worked, and yes, i do have the latest version, I downlaoded it yesterday

2 Things... Let me guess, you didn't #include your original $dll = DllOpen() and Misc.au3? Thought you would have done that, I only pasted the pertinent information silly me.

Anyway, I also see a logic issue with mine, I'm using Coord Mode 2 assuming that you would have used Client Coords, made an option to change it... If you run this example below, I didn't assume you knew to add or change anything.

$color = 0xFF0000
While 1
    Sleep(10)
    If _IsPressed("01") Then
        $aSearch = _PixToMouse(50, $color, 0)
        If Not @error Then
            MouseClick('right', $aSearch[0], $aSearch[1], 1, 0)
        EndIf
    EndIf
WEnd

Func _PixToMouse($iVariant, $iColor, $iWinCoord = 2, $iShade = 0, $iStep = 1)
    $OptPCM = Opt('PixelCoordMode', $iWinCoord)
    $OptMCM = Opt('MouseCoordMode', $iWinCoord)
    Local $aMpos = MouseGetPos(), $aPix
    If IsArray($aMpos) Then
        $aPix = PixelSearch($aMpos[0] - $iVariant, $aMpos[1] - $iVariant, _
            $aMpos[0] + $iVariant, $aMpos[1] + $iVariant, $iShade, $iStep)
        Opt('PixelCoordMode', $OptPCM)
        Opt('MouseCoordMode', $OptMCM)
        If IsArray($aPix) Then
            Return $aPix
        EndIf
    EndIf
    Return SetError(1, 0, 0)
EndFunc

Func _IsPressed($v_R, $v_dll = 'user32.dll')
    $v_R = DllCall($v_dll, 'int', 'GetAsyncKeyState', 'int', '0x' & $v_R)
    Return (Not @error And BitAND($v_R[0], 0x8000) = 0x8000) * 1
EndFunc   ;==>_IsPressed
This is a working example, you just need to changed the $color

Edit, you may want to change _IsPressed('01') to '04', I used '01' to test.

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

  • Moderators

alright, and if i want to change the colr variation and step, i cahnge the number in these,?

Func _PixToMouse($iVariant, $iColor, $iWinCoord = 2, $iShade = 0, $iStep = 1)

rite?

and thank you so much smoke

You wouldn't change them specifically, you would change the call to it.

so if I wanted the variant search to search 20x20, the color to be 0xFFFFFF, the coord search to be screen, the shade variation to be 10, and the step mode to be 10, i would make the call like.

$color = 0xFF0000
While 1
    Sleep(10)
    If _IsPressed("01") Then
        $aSearch = _PixToMouse(20, 0xFFFFFF, 1, 10, 10) ;<<<< Note this is where you change it.
        If Not @error Then
            MouseClick('right', $aSearch[0], $aSearch[1], 1, 0)
        EndIf
    EndIf
WEnd

Func _PixToMouse($iVariant, $iColor, $iWinCoord = 2, $iShade = 0, $iStep = 1)
    $OptPCM = Opt('PixelCoordMode', $iWinCoord)
    $OptMCM = Opt('MouseCoordMode', $iWinCoord)
    Local $aMpos = MouseGetPos(), $aPix
    If IsArray($aMpos) Then
        $aPix = PixelSearch($aMpos[0] - $iVariant, $aMpos[1] - $iVariant, _
            $aMpos[0] + $iVariant, $aMpos[1] + $iVariant, $iShade, $iStep)
        Opt('PixelCoordMode', $OptPCM)
        Opt('MouseCoordMode', $OptMCM)
        If IsArray($aPix) Then
            Return $aPix
        EndIf
    EndIf
    Return SetError(1, 0, 0)
EndFunc

Func _IsPressed($v_R, $v_dll = 'user32.dll')
    $v_R = DllCall($v_dll, 'int', 'GetAsyncKeyState', 'int', '0x' & $v_R)
    Return (Not @error And BitAND($v_R[0], 0x8000) = 0x8000) * 1
EndFunc   ;==>_IsPressed

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

This sitll does not work, and ive tried to see if somethign was rong, i changed the shade variation to 100 and it still wunt pik up the color, so i painted on paint the color and still does not work...

Just to make sure this bot is supposed to do wat i think it does:

When you click the scroll wheel, it scans an area of 50 pixels around the clicked area, if it sees the $color it will right click on it?

$color = 0FFFFF

While 1
    Sleep(10)
    If _IsPressed("04") Then
        $aSearch = _PixToMouse(50, 0x9C2021, 1)
        If Not @error Then
            MouseClick('right', $aSearch[0], $aSearch[1], 1, 0)
        EndIf
    EndIf
WEnd

Func _PixToMouse($iVariant, $iColor, $iWinCoord = 2, $iShade = 0, $iStep = 1)
    $OptPCM = Opt('PixelCoordMode', $iWinCoord)
    $OptMCM = Opt('MouseCoordMode', $iWinCoord)
    Local $aMpos = MouseGetPos(), $aPix
    If IsArray($aMpos) Then
        $aPix = PixelSearch($aMpos[0] - $iVariant, $aMpos[1] - $iVariant, _
            $aMpos[0] + $iVariant, $aMpos[1] + $iVariant, $iShade, $iStep)
        Opt('PixelCoordMode', $OptPCM)
        Opt('MouseCoordMode', $OptMCM)
        If IsArray($aPix) Then
            Return $aPix
        EndIf
    EndIf
    Return SetError(1, 0, 0)
EndFunc

Func _IsPressed($v_R, $v_dll = 'user32.dll')
    $v_R = DllCall($v_dll, 'int', 'GetAsyncKeyState', 'int', '0x' & $v_R)
    Return (Not @error And BitAND($v_R[0], 0x8000) = 0x8000) * 1
EndFunc  ;==>_IsPressed
Link to comment
Share on other sites

you are missing $iColor in pixelsearch, so it use $iShade as color.

I have that in this line:

Func _PixToMouse($iVariant, $iColor, $iWinCoord = 2, $iShade = 0, $iStep = 1)

or do i have to put it somewhere else, if so, where, im very confused, cause smoke did most of this script, i had an earlyier one that almsot workd

Link to comment
Share on other sites

A;right, I got it to work, but for some reason no matter wat color I put in it ssearches for the color black.

$aSearch = _PixToMouse( 100, 0xA52818, 0, 1, 1 )

even though the vcolor is a reddish color,

And jsut confirming..

$aSearch = _PixToMouse( 100, 0xA52818, 0, 1, 1)

. ^^ (radius, color, ?, shade variation, step?) ^^

Link to comment
Share on other sites

  • Moderators

A;right, I got it to work, but for some reason no matter wat color I put in it ssearches for the color black.

$aSearch = _PixToMouse( 100, 0xA52818, 0, 1, 1 )

even though the vcolor is a reddish color,

And jsut confirming..

$aSearch = _PixToMouse( 100, 0xA52818, 0, 1, 1)

. ^^ (radius, color, ?, shade variation, step?) ^^

Here's a nice tall glass of .... Sort it out! You're doing something wrong, not the function, I noticed how you called pixelsearch in the 3rd post, so this doesn't suprise me really.

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

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