Pixel Click

From AutoIt Wiki
Jump to navigation Jump to search

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.

Demonstration

 
 Global $CheckSwap = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")

 Global $MousePrimary, $MouseSecondary

 If $CheckSwap = 1 Then
     $MousePrimary = "right"
     $MouseSecondary = "left"
 Else
     $MousePrimary = "left"
     $MouseSecondary = "right"
 EndIf
 
 ; ************************************************* ;
 ; Change your settings here                         ;
 ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ;
 Global $ExitKey = "{ESC}"
 Global $Color = 0xff00ff
 Global $Left = 0
 Global $Top = 0
 Global $Right = 200
 Global $Bottom = 200
 Global $ClickMouse = $MousePrimary
 Global $SearchResult

 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