Jump to content

ColourUnderMouse


James
 Share

Recommended Posts

Howdy fellow nerds (I may be speaking for myself here, said my Dad),

I got annoyed when looking at a website and I wanted to know what that cool green colour under my mouse was and if my friends were programming games for bots, and I was the only one with access to the game, they would ask me what the colour was and I had to take a screenshot, then find the colour exactly.

Well frankly, its easier to make this than to do that all the f**kin time (Excuse my language, I'm an English Teenager!)

I made this with a little bonus, which I decided to add when I couldn't see the colours, and I thought my script had broken.

If your mouse is over a black colour then the label with the RGB code turns white and if your over white then the label turns black!

*Applauds*, thankyou, thankyou.

Anyways, without further adew here it is:

ColourUnderMouse!

#cs
    Name: Colour Under Mouse
    Author: James Brooks aka Secure_ICT
    Description: Shows colours under the mouse
#ce

#include <GuiConstants.au3>
#include <Color.au3>
#include <Misc.au3>

$DLL = DllOpen("user32.dll")

Global $Color, $hexcolor

$GUI = GUICreate("Test", 170, 50, @DesktopWidth / 2 * 1.66, @DesktopHeight / 4 * 3.50, $WS_POPUP, $WS_EX_TOOLWINDOW)

$cLabel = GUICtrlCreateLabel("", 5, 5, 100, 15)
$iLabel = GUICtrlCreateLabel("RGB formatting", 5, 20, 100, 15)
$eLabel = GUICtrlCreateLabel("Press ESC to escape!", 5, 35, 150, 15)
GUICtrlSetColor(-1, 0x00000)

WinSetOnTop($GUI, "", 1)
GUISetState(@SW_SHOW)

While Not _IsPressed("1B", $DLL)
    Sleep(100)
    $Color = _GetColor()
    GUISetBkColor($Color, $GUI)
    GUISetBkColor($Color, $cLabel)
    _ColorShow()
WEnd

If _IsPressed("11", $DLL) & _IsPressed("72") Then
        ClipPut($hexcolor)
        ConsoleWrite("Colour: " & $hexcolor & " was added to your clipboard!")
EndIf

DllClose($DLL)

WinActivate($GUI)

Func _GetColor()
    $mPos = MouseGetPos()
    Return PixelGetColor($mPos[0], $mPos[1])
EndFunc   ;==>_GetColor

Func _ColorShow()
    $R = Hex(_ColorGetRed($Color), 2)
    $G = Hex(_ColorGetGreen($Color), 2)
    $B = Hex(_ColorGetBlue($Color), 2)
    $hexcolor = "#" & $R & $G & $B
    If $Color = Hex(_ColorGetRed($Color), 2) = "#000000" Then
        GUICtrlSetColor($cLabel, 0xffffff)
        GUICtrlSetColor($iLabel, 0xffffff)
        GUICtrlSetColor($eLabel, 0xffffff)
    ElseIf $Color = Hex(_ColorGetRed($Color), 2) = "#ffffff" Then
        GUICtrlSetColor($cLabel, 0x000000)
        GUICtrlSetColor($iLabel, 0x000000)
        GUICtrlSetColor($eLabel, 0x000000)
    Else
        GUICtrlSetColor($cLabel, 0x000000)
        GUICtrlSetColor($iLabel, 0x000000)
        GUICtrlSetColor($eLabel, 0x000000)
    EndIf
    GUICtrlSetData($cLabel, $hexcolor)
EndFunc   ;==>_ColorShow

Press ESC to escape and Shift+F3 to put the current colour which is under the mouse to the clipboard!

- James

Edit: Minor spelling mistake!

Edit: I used the wrong word! :rolleyes:

Edit: Another spelling mistake.

Edit: Update! Added some more text for information purposes.

Edited by Secure_ICT
Link to comment
Share on other sites

i feel this is a bit over complicated.

simplefyed version

#include <Misc.au3>
#NoTrayIcon
;include misc for the _ispressed fucntion

$gui = GUICreate("",100,20,-1,-1,0x80000000+0x00400000,0x00000008+0x00000080)
$label = GUICtrlCreateLabel("",10,5,80,15,-1,0x00100000)
GUISetState()
$oldcolor = 0
$pause = 0
while 1
    if _IsPressed("1B") then ExitLoop
    if _IsPressed("13") and $pause = 0 Then
        while _IsPressed("13")
            $pause = 1
            sleep(1)
        WEnd
    elseif _IsPressed("13") and $pause = 1 Then
        while _IsPressed("13")
            $pause = 0
            sleep(1)
        WEnd
    EndIf
    $pos = MouseGetPos()
    $color = PixelGetColor($pos[0],$pos[1])
    if $color <> $oldcolor and $pause = 0 then
        GUISetBkColor(Execute("0x" &Hex($color,6)))
        GUICtrlSetData($label,"0x" & Hex($color,6))
        GUICtrlSetColor($label,"0x" & Hex(16777215-$color,6))
        $oldcolor = $color
    EndIf
    sleep(10)
WEnd

to freeze the gui press the break button and esc to exit

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

Howdy fellow nerds (I may be speaking for myself here, said my Dad),

:rolleyes: I think I agree with him.

i feel this is a bit over complicated.

simplefyed version

#include <Misc.au3>
#NoTrayIcon
;include misc for the _ispressed fucntion

$gui = GUICreate("",100,20,-1,-1,0x80000000+0x00400000,0x00000008+0x00000080)
$label = GUICtrlCreateLabel("",10,5,80,15,-1,0x00100000)
GUISetState()
$oldcolor = 0
$pause = 0
while 1
    if _IsPressed("1B") then ExitLoop
    if _IsPressed("13") and $pause = 0 Then
        while _IsPressed("13")
            $pause = 1
            sleep(1)
        WEnd
    elseif _IsPressed("13") and $pause = 1 Then
        while _IsPressed("13")
            $pause = 0
            sleep(1)
        WEnd
    EndIf
    $pos = MouseGetPos()
    $color = PixelGetColor($pos[0],$pos[1])
    if $color <> $oldcolor and $pause = 0 then
        GUISetBkColor(Execute("0x" &Hex($color,6)))
        GUICtrlSetData($label,"0x" & Hex($color,6))
        GUICtrlSetColor($label,"0x" & Hex(16777215-$color,6))
        $oldcolor = $color
    EndIf
    sleep(10)
WEnd

to freeze the gui press the break button and esc to exit

ok thats a lot simplier but Secure's shows a lot more info.

I can do signature me.

Link to comment
Share on other sites

  • 1 year later...

Nice, thanks :)

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

the last time the user posted on this was on the 15th of june 2007 i dont think they check the forums every day for a year and a half to wait for another reply.

Edited by FaT3oYCG

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Link to comment
Share on other sites

the last time the user posted on this was on the 15th of june 2007 i dont think they check the forums every day for a year and a half to wait for another reply.

oh..... the person before me posted reciently bumping it to the front. i thoght it was recient.

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

Since this topic has been bumped then how about this modification? I think it achieves the same result but in fewer steps. What do you think?

#cs
    Name: Colour Under Mouse
    Author: James Brooks aka Secure_ICT
    Description: Shows colours under the mouse
#ce

#include <WindowsConstants.au3>
#include <Color.au3>
#include <Misc.au3>

Local $Color=0,$ESC="1B",$shift="11",$F3="72",$black=0x000000,$white=0xFFFFFF,$DLL=DllOpen("user32.dll")
Global $hexcolor=0

Local $GUI=GUICreate("Test",175,50,@DesktopWidth/2*1.66,@DesktopHeight/4*3.50,$WS_POPUP,$WS_EX_TOOLWINDOW)
Local $cLabel = GUICtrlCreateLabel( "" , 5 , 5 , 100 , 15 )
Local $iLabel = GUICtrlCreateLabel( "Format: RGB" & @CR & "Press ESC to escape!", 5 , 20 , 105 , 30 )

WinSetOnTop( $GUI , "" , 1 )
GUISetState( @SW_SHOW )

Do 
    Sleep( 75 )
    
    $Color = PixelGetColor( MouseGetPos( 0 ) , MouseGetPos( 1 ) )
    
    $hexcolor = Hex(   _ColorGetRed( $Color ) , 2 ) & _
                Hex( _ColorGetGreen( $Color ) , 2 ) & _
                Hex(  _ColorGetBlue( $Color ) , 2 ) 
                
    GUICtrlSetData( $cLabel , "#" & $hexcolor )    
    GUISetBkColor( $Color , $GUI )
    
    If $Color = $black Then        
        GUICtrlSetColor( $cLabel , $white )
        GUICtrlSetColor( $iLabel , $white )        
    Else        
        GUICtrlSetColor( $cLabel , $black )
        GUICtrlSetColor( $iLabel , $black )        
    EndIf    
    
    If _IsPressed( $F3 , $DLL ) Then
        ClipPut( $hexcolor )
        ConsoleWrite( "Colour: " & $hexcolor & " was added to your clipboard!" & @CRLF )
    EndIf
Until _IsPressed( $ESC , $DLL )

DllClose( $DLL )

Exit

edit: code format

Well, how well are the _timer_init() and _timer_diff() functions for timing the execution speed of code? If they are useful then I think I got from the original execution of 0.6 sec to 0.1 sec.

Edited by jaberwocky6669
Link to comment
Share on other sites

OK, I just now saw that AutoIt has a time output in its output pane! Duh!

The time that it takes my modification to find the color of one pixel is 0.101

The original takes 0.666.

I have made more modifications to the code.

#cs
    Name: Colour Under Mouse
    Author: James Brooks aka Secure_ICT
    Description: Shows colours under the mouse
#ce

#include <WindowsConstants.au3>
#include <Color.au3>
#include <Misc.au3>

Local $Color = 0 , $ESC = "1B" , $F3 = "72" , $black = 0x000000 , $white = 0xFFFFFF , $DLL = DllOpen( "user32.dll" )
Global $hexcolor = 0

Local $GUI = GUICreate( "Test" , 175 , 50 , @DesktopWidth / 2 * 1.66 , @DesktopHeight / 4 * 3.50 , $WS_POPUP , $WS_EX_TOOLWINDOW )
Local $cLabel = GUICtrlCreateLabel( "" , 5 , 5 , 105 , 45 )

WinSetOnTop( $GUI , "" , 1 )
GUISetState( @SW_SHOW )

;~ Do  ; I commented these lines out in order to find the execution time of one pixel.
;~     Sleep( 10 )
    
    $Color = PixelGetColor( MouseGetPos( 0 ) , MouseGetPos( 1 ) )
    
    $hexcolor = Hex(   _ColorGetRed( $Color ) , 2 ) & _
                Hex( _ColorGetGreen( $Color ) , 2 ) & _
                Hex(  _ColorGetBlue( $Color ) , 2 ) 
                
    GUICtrlSetData( $cLabel , "#" & $hexcolor & @CR & "Format: RGB" & @CR & "Press ESC to escape!" )
    
    If $Color = $black Then     
        GUICtrlSetColor( $cLabel , $white ) 
    Else        
        GUICtrlSetColor( $cLabel , $black ) 
    EndIf       
    
    GUISetBkColor( $Color , $GUI )
;~ Until _IsPressed( $ESC , $DLL )
    
If _IsPressed( $F3 , $DLL ) Then
    ClipPut( $hexcolor )
    ConsoleWrite( "Colour: " & $hexcolor & " was added to your clipboard!" & @CRLF )
EndIf

DllClose( $DLL )

Exit

Keep in mind that I not trying to outcode the original poster. I only want to learn as much about AutoIt as possible by using trial and error.

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