#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Resources\MouseClicker.ico
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=Клики мышкой в точке нахождения курсора
#AutoIt3Wrapper_Res_Description=Клики мышкой в точке нахождения курсора
#AutoIt3Wrapper_Res_Fileversion=1.0.0.1
#AutoIt3Wrapper_Res_LegalCopyright=©2014 madmasles
#AutoIt3Wrapper_Res_Language=1049
#AutoIt3Wrapper_Res_Icon_Add=Resources\NoClick.ico
#AutoIt3Wrapper_Res_Icon_Add=Resources\Click.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;~ Autit v3.3.8.1
Opt('MustDeclareVars', 1)
Opt('TrayMenuMode', 3)
If WinExists('[TITLE:{EB2660C3-57E0-4220-A11F};CLASS:AutoIt v3]') Then Exit
AutoItWinSetTitle('{EB2660C3-57E0-4220-A11F}')
Global $aHotKeys[2][3], $iRandomPause, $aPause, $iPause, $hLowLevelMouseProc, $hHookEx, $fClick, $iCountMouseDown
If @Compiled Then
TraySetIcon(@ScriptFullPath, 201)
Else
TraySetIcon(@ScriptDir & '\Resources\NoClick.ico')
EndIf
__LoadKeyboardLayoutEngSelf()
OnAutoItExitRegister('_OnExit')
For $i = 0 To 1
__HotKeySet($aHotKeys, $i)
Next
TraySetToolTip('MouseClicker v1.0.0.1' & @LF & 'Начало/конец кликов: "' & $aHotKeys[0][0] & '"' & @LF & 'Выход: "' & $aHotKeys[1][0] & '"')
TrayTip('MouseClicker v1.0.0.1', 'Горячие клавиши управления программой:' & @LF & 'Начала/конца кликов: ............... ' & $aHotKeys[0][0] & @LF & _
'Выхода из программы: ............... ' & $aHotKeys[1][0], 5, 1)
AdlibRegister('_KillTrayTip', 5000)
ReDim $aHotKeys[1][3]
_SetMouseClickDownDelay()
_GetPauseBetweenClicks($iRandomPause, $aPause, $iPause)
While 1
Sleep(20)
If $fClick Then
If $iCountMouseDown Then
;~ ConsoleWrite('Start Click' & @LF)
Do
MouseClick('primary')
If $iRandomPause Then
Sleep(Random($aPause[0], $aPause[1], 1))
Else
Sleep($iPause)
EndIf
Until Not $iCountMouseDown
;~ ConsoleWrite('End Click' & @LF)
EndIf
EndIf
WEnd
Func _BeginEndClick()
HotKeySet($aHotKeys[0][1])
$fClick = Not $fClick
;~ ConsoleWrite('BeginEndClick :' & $fClick & @LF)
If $fClick Then
If @Compiled Then
TraySetIcon(@ScriptFullPath, 202)
Else
TraySetIcon(@ScriptDir & '\Resources\Click.ico')
EndIf
_SetHook($hHookEx, $hLowLevelMouseProc)
Else
If @Compiled Then
TraySetIcon(@ScriptFullPath, 201)
Else
TraySetIcon(@ScriptDir & '\Resources\NoClick.ico')
EndIf
_UnHook($hHookEx, $hLowLevelMouseProc)
$iCountMouseDown = 0
EndIf
HotKeySet($aHotKeys[0][1], $aHotKeys[0][2])
EndFunc ;==>_BeginEndClick
Func _SetHook(ByRef $h_HookEx, ByRef $h_LowLevelMouseProc)
If $h_LowLevelMouseProc Or $h_HookEx Then _UnHook($h_HookEx, $h_LowLevelMouseProc)
Local Const $__WH_MOUSE_LL = 14
Local $i_Err = 1, $a_Res, $h_SelfModul, $p_LowLevelMouseProc
Do
$a_Res = DllCall('kernel32.dll', 'handle', 'GetModuleHandleW', 'ptr', 0)
If (@error) Or (Not $a_Res[0]) Then ExitLoop
$h_SelfModul = $a_Res[0]
$h_LowLevelMouseProc = DllCallbackRegister('_LowLevelMouseProc', 'int', 'int;wparam;lparam')
If Not $h_LowLevelMouseProc Then ExitLoop
$p_LowLevelMouseProc = DllCallbackGetPtr($h_LowLevelMouseProc)
If Not $p_LowLevelMouseProc Then ExitLoop
$a_Res = DllCall('user32.dll', 'handle', 'SetWindowsHookEx', 'int', $__WH_MOUSE_LL, 'ptr', $p_LowLevelMouseProc, _
'handle', $h_SelfModul, 'dword', 0)
If (@error) Or (Not $a_Res[0]) Then ExitLoop
$h_HookEx = $a_Res[0]
$i_Err = 0
Until 1
If $i_Err Then
_UnHook($h_HookEx, $h_LowLevelMouseProc)
Return 0
EndIf
Return 1
EndFunc ;==>_SetHook
Func _UnHook(ByRef $h_HookEx, ByRef $h_LowLevelMouseProc)
Local $i_Err = 1, $a_Res
If $h_HookEx Then
$a_Res = DllCall('user32.dll', 'int', 'UnhookWindowsHookEx', 'handle', $h_HookEx)
If (@error) Or (Not $a_Res[0]) Then Return 0
$h_HookEx = 0
EndIf
If $h_LowLevelMouseProc Then
DllCallbackFree($h_LowLevelMouseProc)
$h_LowLevelMouseProc = 0
EndIf
Return 1
EndFunc ;==>_UnHook
Func _LowLevelMouseProc($i_Code, $_wParam, $_lParam)
Local Const $__WM_LBUTTONDOWN = 0x0201, $__WM_LBUTTONUP = 0x0202
If $i_Code >= 0 Then
Switch $_wParam
Case $__WM_LBUTTONDOWN
$iCountMouseDown += 1
Case $__WM_LBUTTONUP
$iCountMouseDown -= 1
EndSwitch
EndIf
Local $a_Res = DllCall('user32.dll', 'lresult', 'CallNextHookEx', 'handle', $hHookEx, 'int', $i_Code, 'wparam', $_wParam, 'lparam', $_lParam)
If @error Then Return -1
Return $a_Res[0]
EndFunc ;==>_LowLevelMouseProc
Func __HotKeySet(ByRef $a_HotKeys, $i_Index)
Local $s_Ini = @ScriptDir & '\MouseClicker.ini', $a_Info[2] = ['BeginEndClick', 'Exit'], $s_ReadIni, _
$a_ModKeys[5][2] = [[4],['Alt', '!'],['Shift', '+'],['Ctrl', '^'],['Win', '#']], $a_Tmp, $s_ModKey, _
$s_Key
If Not FileExists($s_Ini) Then Exit MsgBox(16, 'Ошибка', 'Отсутствует файл настроек "MouseClicker.ini".')
Switch $i_Index
Case 0, 1
Case Else
Exit MsgBox(16, 'Ошибка', 'Не корректное значение $i_Index.')
EndSwitch
$s_ReadIni = StringStripWS(IniRead($s_Ini, 'HotKeys', $a_Info[$i_Index], 'error'), 8)
If (Not $s_ReadIni) Or ($s_ReadIni = 'error') Then Exit MsgBox(16, 'Ошибка', 'Не корректное значение ключа "' & $a_Info[$i_Index] & '".')
If StringInStr($s_ReadIni, '+') Then
$a_Tmp = StringSplit($s_ReadIni, '+')
If $a_Tmp[0] < 2 Then Exit MsgBox(16, 'Ошибка', 'Не корректное значение ключа "' & $a_Info[$i_Index] & '".')
For $i = 1 To $a_Tmp[0]
If Not $a_Tmp[$i] Then Exit MsgBox(16, 'Ошибка', 'Не корректное значение ключа "' & $a_Info[$i_Index] & '".')
Next
For $i = 1 To $a_ModKeys[0][0]
If $a_Tmp[1] = $a_ModKeys[$i][0] Then
$s_ModKey = $a_ModKeys[$i][1]
$a_HotKeys[$i_Index][0] = $a_ModKeys[$i][0] & '+'
ExitLoop
EndIf
Next
If Not $s_ModKey Then Exit MsgBox(16, 'Ошибка', 'Не корректное значение горячей клавиши-модификатора.')
$s_Key = StringLower($a_Tmp[2])
Else
$s_Key = StringLower($s_ReadIni)
EndIf
If $i_Index Then
If $s_Key = 'esc' Then
$s_Key = '{Esc}'
$a_HotKeys[$i_Index][0] &= 'Esc'
Else
If Not StringRegExp($s_Key, '^[a-z]$') Then Exit MsgBox(16, 'Ошибка', 'Не корректное значение горячей клавиши.')
$a_HotKeys[$i_Index][0] &= $s_Key
EndIf
If $a_HotKeys[1][0] = $a_HotKeys[0][0] Then Exit MsgBox(16, 'Ошибка', 'Горячие клавиши на разные действия совпадают.')
Else
If Not StringRegExp($s_Key, '^[a-z]$') Then Exit MsgBox(16, 'Ошибка', 'Не корректное значение горячей клавиши.')
$a_HotKeys[$i_Index][0] &= $s_Key
EndIf
;~ ConsoleWrite($s_ModKey & $s_Key & @LF)
$aHotKeys[$i_Index][1] = $s_ModKey & $s_Key
$aHotKeys[$i_Index][2] = '_' & $a_Info[$i_Index]
HotKeySet($s_ModKey & $s_Key, '_' & $a_Info[$i_Index])
EndFunc ;==>__HotKeySet
Func _GetPauseBetweenClicks(ByRef $i_RandomPause, ByRef $a_Pause, ByRef $i_Pause)
Local $s_Ini = @ScriptDir & '\MouseClicker.ini', $i_ReadIni
$i_ReadIni = Int(IniRead($s_Ini, 'PauseBetweenClicks', 'Random', '0'))
If Not $i_ReadIni Then
$i_RandomPause = 0
$a_Pause = 0
$i_Pause = Int(IniRead($s_Ini, 'PauseBetweenClicks', 'PauseMin', '50'))
Switch $i_Pause
Case 20 To 1000
Case Else
$i_Pause = 50
EndSwitch
Else
$i_RandomPause = 1
If IsArray($a_Pause) Then
ReDim $a_Pause[2]
Else
Dim $a_Pause[2]
EndIf
$a_Pause[0] = Int(IniRead($s_Ini, 'PauseBetweenClicks', 'PauseMin', '50'))
Switch $a_Pause[0]
Case 20 To 900
Case Else
$a_Pause[0] = 50
EndSwitch
$a_Pause[1] = Int(IniRead($s_Ini, 'PauseBetweenClicks', 'PauseMax', '150'))
Switch $a_Pause[1]
Case $a_Pause[0] + 50 To 1000
Case Else
$a_Pause[1] = $a_Pause[0] + 100
EndSwitch
EndIf
Return 1
EndFunc ;==>_GetPauseBetweenClicks
Func _SetMouseClickDownDelay()
Local $s_Ini = @ScriptDir & '\MouseClicker.ini', $i_MouseClickDownDelay
$i_MouseClickDownDelay = Int(IniRead($s_Ini, 'MouseOptoin', 'ClickDownDelay', '10'))
Switch $i_MouseClickDownDelay
Case 10 To 50
Opt('MouseClickDownDelay', $i_MouseClickDownDelay)
EndSwitch
EndFunc ;==>_SetMouseClickDownDelay
Func _KillTrayTip()
AdlibUnRegister('_KillTrayTip')
TrayTip('MouseClicker', '', 1)
EndFunc ;==>_KillTrayTip
Func __LoadKeyboardLayoutEngSelf()
Local Const $__KLF_ACTIVATE = 0x00000001, $__KLF_SETFORPROCESS = 0x00000100
Local $a_Res = DllCall('user32.dll', 'long', 'LoadKeyboardLayoutW', 'wstr', '00000409', 'uint', BitOR($__KLF_ACTIVATE, $__KLF_SETFORPROCESS))
If (@error) Or (Not $a_Res[0]) Or (Not StringInStr(Hex($a_Res[0]), '0409')) Then Return 0
Return 1
EndFunc ;==>__LoadKeyboardLayoutEngSelf
Func _OnExit()
_UnHook($hHookEx, $hLowLevelMouseProc)
EndFunc ;==>_OnExit
Func _Exit()
Exit
EndFunc ;==>_Exit