Jump to content

Simple script that clicks when mouse hovers over a chosen color


twisted
 Share

Recommended Posts

Hi, just started off using AutoIt and I'm not very good. Been trying to get this working for some time. It's kind of bare right now because the GUI is there for now just to let me know that the script is running. I'm trying to get it working before I "beautify" the whole thing.

$aLoop = 0
$bLoop = 1
Dim $set, $posx, $posy, $rainbow

HotKeySet("{ESC}", "Terminate")
HotKeySet("{HOME}", "SetColor")
HotKeySet("{END}", "ToggleSeek")

Func Terminate()
    Exit 0
EndFunc

Func SetColor()
    $set = $rainbow
    MsgBox ( 4096, "", $set)
EndFunc

Func ToggleSeek()
    If $aLoop = 0 Then
        $aLoop = 1
    ElseIf $aLoop = 1 Then
        $aLoop = 0
    EndIf
EndFunc

GUICreate ( "Colour Click", 300, 50 )
GUICtrlCreateLabel ("Colour Click Running! Press Esc to quit.", 10, 10)
GUISetState(@SW_SHOW)

While $bLoop = 1
    $posx = MouseGetPos ( 0 )
    $posy = MouseGetPos ( 1 )
    $rainbow = PixelGetColor ( $posx , $posy)
WEnd

While $aLoop = 1
    If $rainbow = $set Then
        MouseClick ( "left" )
        Sleep ( 500 )
    EndIf
WEnd

Basically it's supposed to set the color once you hit the HOME key and it seems to work because the message box that pops up whenever i hit HOME shows the color code. However, I can't seem to get it clicking by hitting the END key.

Any help would be much appreciated, can't seem to get it working myself. I hope it doesn't turn out to be some really stupid mistake on my part.

Thanks!

Link to comment
Share on other sites

You were close. All you had to do was get rid of the 2nd while and add the if..then into your first one. I tested using paint and setting to a color like red, selected the paint bucket and when i moused over it it would change the color so i knew it was working.

$aLoop = 0
$bLoop = 1
Dim $set, $posx, $posy, $rainbow

HotKeySet("{ESC}", "Terminate")
HotKeySet("{HOME}", "SetColor")
HotKeySet("{END}", "ToggleSeek")

Func Terminate()
    Exit 0
EndFunc

Func SetColor()
    $set = $rainbow
    MsgBox ( 4096, "", $set)
EndFunc

Func ToggleSeek()
    If $aLoop = 0 Then
        $aLoop = 1
    ElseIf $aLoop = 1 Then
        $aLoop = 0
    EndIf
EndFunc

GUICreate ( "Colour Click", 300, 50 )
GUICtrlCreateLabel ("Colour Click Running! Press Esc to quit.", 10, 10)
GUISetState(@SW_SHOW)

While $bLoop = 1
    $posx = MouseGetPos ( 0 )
    $posy = MouseGetPos ( 1 )
    $rainbow = PixelGetColor ( $posx , $posy)
        If $rainbow = $set Then
        MouseClick("Left")
        Sleep ( 500 )
    EndIf
WEnd

Good luck with the rest

Link to comment
Share on other sites

Another look...

Dim $aLoop = 0, $bLoop = 1
Dim $set, $posx, $posy, $rainbow

HotKeySet("{ESC}", "Terminate")
HotKeySet("{HOME}", "SetColor")
HotKeySet("{END}", "ToggleSeek")

GUICreate("Colour Click", 300, 50)
GUICtrlCreateLabel("Colour Click Running! Press Esc to quit.", 10, 10)
GUISetState(@SW_SHOW)


While GUIGetMsg() <> -3 ; different then exit
    
    If $bLoop = 1 Then
        $posx = MouseGetPos(0)
        $posy = MouseGetPos(1)
        $rainbow = PixelGetColor($posx, $posy)
    EndIf
    
    If $aLoop = 1 Then
        If $rainbow = $set Then
            MouseClick("left")
            Sleep(500)
        EndIf
    EndIf
    
WEnd


; ---- Functions ---------

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func SetColor()
    $set = $rainbow
    MsgBox(4096, "", $set)
EndFunc   ;==>SetColor

Func ToggleSeek()
    If $aLoop = 0 Then
        $aLoop = 1
    ElseIf $aLoop = 1 Then
        $aLoop = 0
    EndIf
    ToolTip("aLoop = " & $aLoop & @CRLF & "bLoop = " & $bLoop & @CRLF & "Color = " & $rainbow & "  ", 10, 10, "... 8)", 1)
EndFunc   ;==>ToggleSeek

8)

NEWHeader1.png

Link to comment
Share on other sites

I tryed Valuater's and had some problems getting it to work, dont know if i was just me or something but once i changed the way he had the While i got it to work

here's what i had to change it to to get it to work on mine, agian good luck

While GUIGetMsg() <> -3 ; different then exit
    $posx = MouseGetPos(0)
    $posy = MouseGetPos(1)
    $rainbow = PixelGetColor($posx, $posy)
    
    If $rainbow = $set Then
            MouseClick("left")
            Sleep(500)
        EndIf
WEnd
Edited by Rental
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...