Sign in to follow this  
Followers 0
bigassmuffin

pixel search around clicked area

16 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

[center]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.[/center]

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

See my edit. Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

See my edit.

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

Share this post


Link to post
Share on other sites

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.

[center]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.[/center]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Lar.

it sais variable used without being declared

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

[center]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.[/center]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

[center]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.[/center]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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?) ^^

Share this post


Link to post
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?) ^^

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.

[center]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.[/center]

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  
Followers 0