Pixel Click: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
(Reversed Vandalism)
(No difference)

Revision as of 11:02, 8 November 2006

Purpose:

Search for a pixel of a specific colour to click on, loop this process indefinitely, and provide a hotkey to stop the entire thing.

Illustrates:

  • How to use PixelSearch() to find a specific coloured pixel.
  • How to use MouseClick() to click on a specific point.
  • How to check the registry to see if the mouse buttons are swapped.
  • How to set a HotKey to exit a script.
Dim $ClickMouse, $MousePrimary, $MouseSecondary, $ExitKey
Dim $Color, $Left, $Top, $Right, $Bottom, $SearchResult, $CheckSwap

$CheckSwap = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")
If $CheckSwap = 1 Then
	$MousePrimary = "right"
	$MouseSecondary = "left"
Else
	$MousePrimary = "left"
	$MouseSecondary = "right"
EndIf

; ************************************************* ;
; Change your settings here                         ;
; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ;
$ExitKey = "{ESC}"
$Color = 0xff00ff
$Left = 0
$Top = 0
$Right = 200
$Bottom = 200
$ClickMouse = $MousePrimary
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ;
; Change your settings here                         ;
; ************************************************* ;

HotKeySet($ExitKey, '_Exit')

While 1
	$SearchResult = PixelSearch($Left, $Top, $Right, $Bottom, $Color)
	If Not @error Then
		MouseClick($ClickMouse, $SearchResult[0], $SearchResult[1], 1, 0)
	EndIf
WEnd

Func _Exit()
	Exit
EndFunc