Sign in to follow this  
Followers 0
84cr250

how to get color 25pixels away from pointer

9 posts in this topic

so my problem is my mouse isn't a standerd mouse its 2x bigger. So when i use the 'AutoIt Window Info' is just comes back with the color of my pointer. so what i need to know is there a way to cheak the color of something like 20 pixels up and 20 pixels left of the pointer

i have this script but i cant use it because i cant get the colors i need. i tryed for 2 days (off and on) then i found out im just getting the colors of my mouse. (lol thats why i could only find 7 different colors with it lol)

HotKeySet("{esc}","close")

Opt('PixelCoordMode', 2)

Opt('MouseCoordMode', 2)

Global $Mpos = '', $Color = XXXXXXXXXX <----- i need the color to put here

While 1

$Mpos = MouseGetPos()

If IsArray($Mpos) Then

$PixColor = PixelGetColor($Mpos[0], $Mpos[1])

If ($PixColor == $Color) Then

MsgBox(0, 'Color Found', 'X: ' & $Mpos[0] & ' Y: ' & $Mpos[1])

EndIf

ToolTip('Xcoord = ' & $Mpos[0] & @CR & 'Ycoord = ' & $Mpos[1] & @CR & 'Color = ' & '0x' & Hex($PixColor, 6))

EndIf

Sleep(10)

WEnd

func close()

Exit

EndFunc

thanks for any help, im new to this so there might just be a really easy fix to this that im not aware of.

Share this post


Link to post
Share on other sites



instead of referencing $mpos[0] and $mpos[1], you can do $mpos[0]-20 & $mpos[1]-20


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

instead of referencing $mpos[0] and $mpos[1], you can do $mpos[0]-20 & $mpos[1]-20

......that simple is it?

Well thanks for the quick answer

Share this post


Link to post
Share on other sites

......that simple is it?

Well thanks for the quick answer

No problem, glad to help

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

so now i have this but it only tells me the color when i run the program and every time i press the "OK" botton

is there a way for it to up date itself every 500ms instead of when i just run it

because i have to find the colors i need befor i can use my other script to search for them

Opt('PixelCoordMode', 2)

Opt('MouseCoordMode', 2)

Global $Mpos

While 1

$Mpos = MouseGetPos()

$PixColor = PixelGetColor($Mpos[0]-20, $Mpos[1]-20)

MsgBox(0, 'Color Found', 'X: ' & $Mpos[0]-20 & ' Y: ' & $Mpos[1]-20 & 'Color = ' & '0x' & Hex($PixColor, 6))

WEnd

Edited by 84cr250

Share this post


Link to post
Share on other sites

Hi 84cr, please use the autoit tags to syntax highlight your code, like this:

Opt('PixelCoordMode', 2)
Opt('MouseCoordMode', 2)

HotKeySet("q","Result")
AdlibRegister("Update",500) ; <====
Global $Color

While 1 ;You could put a sleep in here if you'd like.
WEnd

Func Result()
    MsgBox(0,"Color =",$Color)
EndFunc

Func Update() ; <====
    $Color = PixelGetColor(MouseGetPos(0)-20, MouseGetPos(1)-20)
EndFunc

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

so now i have this but it only tells me the color when i run the program and every time i press the "OK" botton

is there a way for it to up date itself every 500ms instead of when i just run it

because i have to find the colors i need befor i can use my other script to search for them

Opt('PixelCoordMode', 2)

Opt('MouseCoordMode', 2)

Global $Mpos

While 1

$Mpos = MouseGetPos()

$PixColor = PixelGetColor($Mpos[0]-20, $Mpos[1]-20)

MsgBox(0, 'Color Found', 'X: ' & $Mpos[0]-20 & ' Y: ' & $Mpos[1]-20 & 'Color = ' & '0x' & Hex($PixColor, 6))

WEnd

You could use a GUI instead of a MsgBox - MsgBox is blocking, meaning that no other code can run while it is open, so it's a little difficult to update (unless you time it out and recreate it every second, which I think would just be annoying) The following code will update automatically no matter where you move your mouse:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{ESC}","Close")
HotKeySet("{F9}","Copy")

Opt('PixelCoordMode', 1)
Opt('MouseCoordMode', 1)
Global $Mpos, $PixColor

$mousebox = GUICreate("",150,150,0,0,BitOR($WS_CAPTION, $WS_POPUP),$WS_EX_TOPMOST)
GUICtrlCreateLabel("X pos:",10,10,80,25)
GUICtrlCreateLabel("Y pos:",10,40,80,25)
GUICtrlCreateLabel("Color:",10,70,80,25)
$mousex = GUICtrlCreateLabel("",60,10,80,25)
$mousey = GUICtrlCreateLabel("",60,40,80,25)
$mousecolor = GUICtrlCreateLabel("",60,70,80,25)
$mousecolorex = GUICtrlCreateGraphic(10,100,130,30)
GUISetState()

While GUIGetMsg()<>$GUI_EVENT_CLOSE
$Mpos = MouseGetPos()
$PixColor = PixelGetColor($Mpos[0], $Mpos[1])
GUICtrlSetData($mousex,$Mpos[0])
GUICtrlSetData($mousey,$Mpos[1])
GUICtrlSetData($mousecolor,Hex($PixColor, 6))
GUICtrlSetBkColor($mousecolorex,"0x"&Hex($PixColor, 6))
sleep(10)
WEnd

Func Close()
    Exit
EndFunc

Func Copy()
    ClipPut($Mpos[0]&", "&$Mpos[1]&", 0x"&Hex($PixColor, 6))
EndFunc

I changed the coordinate modes to 1 so they give you the position on the screen, not the client area of the window, as this usually makes more sense to get the absolute screen position. It technically updates about 100 times a second, I did this so it doesn't kill the CPU. Also, I put in the offset, but with this code it's not really needed, it will give the color even at the tip of the mouse.

Edit: changed the code to set the window always on top, to map Esc to a hotkey to exit the script, and to map F9 to a function to copy the coordinates and color code to the clipboard

Edited by NinjaGeek

Share this post


Link to post
Share on other sites

You could use a GUI instead of a MsgBox

Or a Tooltip(), that's what i usually use for checking coords etc

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

NinjaGeek killed the nail in head... ;)

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