Jump to content

Get the mouse cursor color


mizou
 Share

Recommended Posts

Hi.

I've been searching for this for a while now but since I can't find an answer I'll ask it directly.

Is there a way to check the mouse cursor color without having to make screenshots and analyzing the area around the mouse position when it was taken?* (since I guess it's resource consuming if it has to be done like 10-20 per second to be fluent)

Thanks !

*PixelSearch() looks for pixels beneath the cursor... it's useless to me

Edited by mizou
Link to comment
Share on other sites

HI,

maybe MouseGetPos and PixelGetColor

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Ty I've seen those in the docs but this doesn't fit my needs since it searches for the pixel under the pointer...not the mouse pointer (cursor)'s colors. And there's nothing about layers so that I could specify that I'm searching for the top-most screen colors (since obviously the pointer is always above all windows)...

Link to comment
Share on other sites

The color of the actual mouse cursor? Hmm, well that could be a little complicated. I mean, looking at my - animated - cursor right now, there's probably over 10 shades of gray, 5 shades of orange, 5 shades of brown, and that's in one frame of the cursor's animation, next frame has new colours. So, how would you even do this for cursors like that?

Back toward an answer, there are API functions called GetCursor, and CopyIcon, these might be a step in the right direction, something to look into maybe? I'm honestly not too sure though.

Link to comment
Share on other sites

Hi,

???

HotKeySet("1", 'start_getColorUnderCursor')

While 1
    Sleep(100)
WEnd

Func start_getColorUnderCursor()
    ConsoleWrite(_getColorUnderCursor() & @CRLF)
EndFunc

Func _getColorUnderCursor()
    Local $pos_A = MouseGetPos()
    MouseMove($pos_A[0] + 1, $pos_A[1], 0)
    Local $color = PixelGetColor($pos_A[0], $pos_A[1])
    MouseMove($pos_A[0], $pos_A[1], 0)
    Return $color
EndFunc   ;==>_getColorUnderCursor

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Doesn't tell you anything about the cursor color, but you can get the ID number, type and handle:

#Include <WinAPI.au3>

HotKeySet("{ESC}", "_Quit")

;create an array that tells us the meaning of an ID Number
Global $IDs[16] = ["Unknown", "AppStarting", "Arrow", "Cross", "Help", "IBeam", "Icon", "No", _
        "Size", "SizeAll", "SizeNESW", "SizeNS", "SizeNWSE", "SizeWE", "UpArrow", "Wait"]

While 1
    $iCursor = MouseGetCursor()
    $avCursor = _WinAPI_GetCursorInfo()
    ToolTip("ID = " & $iCursor & @LF & "Type = " & $IDs[$iCursor] & @LF & "Handle = " & $avCursor[2])
    Sleep(50)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Somehow I can't get understood :/

well.. It seems Saunders did. I can code what you tried to write to help me.. that shows the color under the cursor.. just as you named your function. But that I don't need, I need the color of the actual cursor itself ! (don't worry Saunders..once I can do that it's easy to get what I want to work)

I've been modifying the Zoom example file so I get only one GUI acting as a magnifier (using the _ScreenCapture_Capture) and some _GDIPlus functions, still it doesn't work since it only capture screen area (100x100pix around the pointer) UNDER the pointer...the mouse cursor doesn't show so it's not what I need.

Here is the little code (modified from AutoIt's example) to make a magnifier:

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <GUIConstants.au3>
#include <Misc.au3>
HotKeySet("{ESC}","QuitIt")
Opt("MustDeclareVars", 1)

Global $hBMP, $hGUI1, $hBitmap, $hGraphic1, $mousepos

$hGUI1 = GUICreate("Magnifier", 100, 100, 0,   0)
GUISetState()

While 1
$mousepos = MouseGetPos()
$hBMP = _ScreenCapture_Capture("", $mousepos[0]-50,$mousepos[1]-50,$mousepos[0]+50,$mousepos[1]+50)

; Initialize GDI+ library and load image
_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

; Draw 100x100 around the mouse pointer
$hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($hGUI1)
_GDIPlus_GraphicsDrawImage($hGraphic1, $hBitmap, 0, 0)

_GDIPlus_GraphicsDispose($hGraphic1)
_GDIPlus_ImageDispose($hBitmap)
_WinAPI_DeleteObject($hBmp)
_GDIPlus_Shutdown()
If GUIGetMsg() == $GUI_EVENT_CLOSE Then QuitIt()
WEnd

Func QuitIt()
    Exit
EndFunc

When I'll find (or maybe with some help ^^) how to make the same thing with the cursor showing in the magnifier as I move the mouse around my screen... I'll win !

Edited by mizou
Link to comment
Share on other sites

Doesn't tell you anything about the cursor color, but you can get the ID number, type and handle:

#Include <WinAPI.au3>

HotKeySet("{ESC}", "_Quit")

;create an array that tells us the meaning of an ID Number
Global $IDs[16] = ["Unknown", "AppStarting", "Arrow", "Cross", "Help", "IBeam", "Icon", "No", _
        "Size", "SizeAll", "SizeNESW", "SizeNS", "SizeNWSE", "SizeWE", "UpArrow", "Wait"]

While 1
    $iCursor = MouseGetCursor()
    $avCursor = _WinAPI_GetCursorInfo()
    ToolTip("ID = " & $iCursor & @LF & "Type = " & $IDs[$iCursor] & @LF & "Handle = " & $avCursor[2])
    Sleep(50)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:)

Thanks but I've alsoo seen that ^_^ It ain't what I need either since both cursors are classified as Unknown so there's no way to differentiate them. Edited by mizou
Link to comment
Share on other sites

Thanks but I've alsoo seen that ^_^ It ain't what I need either since both cursors are classified as Unknown so there's no way to differentiate them.

Understood, but does the HANDLE change?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

tsss tssss.. nevermind I found.

In ScreenCapture.au3 (/Include/) ...the _ScreenCapture_Capture has this parameter :

$fCursor - If True the cursor will be captured with the image

thus it's quite easy now.. all I gotta do is analyze the pic to check cursor changing but I hope it won't be killing my resources too much .. If there's a lighter solution I don't mind knowing it :)

Link to comment
Share on other sites

Understood, but does the HANDLE change?

:)

oh my god I guess I need some rest... All my apologies PsaltyDS...I've read your answer too quick since I was half searching on my own too..I thought you used MouseGetCursor only.. as I tried already but this doesn't give you the handle..only the ID. Yes your answer fits my need since -of course- then handle is different.

I love you! .. well not really but still you get all my gratitude ^_^ Thank you !!

*** sweat drops thinking of the heavy brute answer I was about to code hahahah ***

Posted Image

Edited by mizou
Link to comment
Share on other sites

oh my god I guess I need some rest... All my apologies PsaltyDS...I've read your answer too quick since I was half searching on my own too..I thought you used MouseGetCursor only.. as I tried already but this doesn't give you the handle..only the ID. Yes your answer fits my need since -of course- then handle is different.

I love you! .. well not really but still you get all my gratitude ^_^ Thank you !!

*** sweat drops thinking of the heavy brute answer I was about to code hahahah ***

Take a break, have some Egg Nog.

Merry Christmas!

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...