Pixel Click: Difference between revisions
Jump to navigation
Jump to search
(Reversed Vandalism) |
(Syntax Highlighting, code cleanup, and wikify) |
||
Line 1: | Line 1: | ||
=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. | 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:''' | '''Illustrates:''' | ||
* How to use PixelSearch() to find a specific coloured pixel. | * How to use PixelSearch() to find a specific coloured pixel. | ||
* How to use MouseClick() to click on a specific point. | * How to use MouseClick() to click on a specific point. | ||
Line 10: | Line 8: | ||
* How to set a HotKey to exit a script. | * How to set a HotKey to exit a script. | ||
=Demonstration= | |||
<syntaxhighlight lang="autoit"> | |||
Global $CheckSwap = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons") | |||
$CheckSwap = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons") | |||
Global $MousePrimary, $MouseSecondary | |||
If $CheckSwap = 1 Then | If $CheckSwap = 1 Then | ||
$MousePrimary = "right" | |||
$MouseSecondary = "left" | |||
Else | Else | ||
$MousePrimary = "left" | |||
$MouseSecondary = "right" | |||
EndIf | EndIf | ||
Line 25: | Line 25: | ||
; Change your settings here ; | ; Change your settings here ; | ||
; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ; | ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ; | ||
$ExitKey = "{ESC}" | Global $ExitKey = "{ESC}" | ||
$Color = 0xff00ff | Global $Color = 0xff00ff | ||
$Left = 0 | Global $Left = 0 | ||
$Top = 0 | Global $Top = 0 | ||
$Right = 200 | Global $Right = 200 | ||
$Bottom = 200 | Global $Bottom = 200 | ||
$ClickMouse = $MousePrimary | Global $ClickMouse = $MousePrimary | ||
Global $SearchResult | |||
HotKeySet($ExitKey, '_Exit') | HotKeySet($ExitKey, '_Exit') | ||
While 1 | While 1 | ||
$SearchResult = PixelSearch($Left, $Top, $Right, $Bottom, $Color) | |||
If Not @error Then | |||
MouseClick($ClickMouse, $SearchResult[0], $SearchResult[1], 1, 0) | |||
EndIf | |||
WEnd | WEnd | ||
Func _Exit() | Func _Exit() | ||
Exit | |||
EndFunc | EndFunc | ||
</syntaxhighlight> |
Revision as of 14:09, 10 November 2012
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