[AAuto] 纯文本查看 复制代码
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Misc.au3>
#include <Timers.au3>
#include <TabConstants.au3>
#include <SliderConstants.au3>
#include <ColorConstants.au3>
#include <Math.au3>
#include <Array.au3>
#include <ScreenCapture.au3>
#include <GDIPlus.au3>
Opt("GUIOnEventMode", 1) ; 使用事件模式
; ==================== 全局变量 ====================
Global $g_hMainGUI, $g_hTab, $g_hTab1, $g_hTab2, $g_hTab3
; 坐标捕捉相关变量
Global $g_bCapturing = False, $g_hHook = 0, $g_hHookProc = 0, $g_hLastActiveWin = 0, $g_bFirstClick = True
Global $g_lblInfo, $g_btnCapture, $g_lblScreenPos, $g_lblWindowPos, $g_lblCapturedScreenPos, $g_lblCapturedWindowPos, $g_lblActiveWinInfo
; 智能点击器相关变量
Global $g_bMonitoring = False, $g_bEmergencyStop = False
Global $g_iClickCount = 0, $g_iLastClickTime = 0
Global $g_aClickPos[2] = [0, 0]
Global $g_iNormalDelay = 1000, $g_iDoubleClickDelay = 500, $g_iDoubleInterval = 200, $g_iIntervalDelay = 2000
Global $g_iNormalTimes = 1, $g_iDoubleTimes = 2, $g_iIntervalTimes = 10
Global $g_bNormalInfinite = False, $g_bDoubleInfinite = False, $g_bIntervalInfinite = False
Global $g_lblPosition, $g_lblStatus, $g_btnStart
Global $g_radioNormal, $g_radioDouble, $g_radioInterval
Global $g_hNormalDelay, $g_hDoubleClickDelay, $g_hDoubleInterval, $g_hIntervalDelay
Global $g_hNormalTimes, $g_hDoubleTimes, $g_hIntervalTimes
Global $g_hNormalInfinite, $g_hDoubleInfinite, $g_hIntervalInfinite
; 颜色拾取器相关变量
Global $g_hColorDisplay, $g_idHexInput, $g_idCopyHex, $g_idRedSlider, $g_idGreenSlider, $g_idBlueSlider
Global $g_idRedValue, $g_idGreenValue, $g_idBlueValue, $g_idCopyRGB, $g_idPickColor, $g_idExtractColors
Global $g_idCommonColorBtns[36], $g_aCommonColorValues[36]
; ==================== 主界面创建 ====================
Func CreateMainGUI()
$g_hMainGUI = GUICreate("屏幕拾取工具", 600, 700)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
; 创建选项卡
$g_hTab = GUICtrlCreateTab(10, 10, 580, 680)
; 标签页1 - 坐标捕捉
$g_hTab1 = GUICtrlCreateTabItem("窗口坐标捕捉")
CreateCoordinateCaptureTab()
; 标签页2 - 智能点击器
$g_hTab2 = GUICtrlCreateTabItem("智能点击器")
CreateAutoClickerTab()
; 标签页3 - 颜色拾取器
$g_hTab3 = GUICtrlCreateTabItem("颜色拾取器")
CreateColorPickerTab()
GUICtrlCreateTabItem("") ; 结束选项卡创建
GUISetState(@SW_SHOW, $g_hMainGUI)
; 初始化GDIPlus
_GDIPlus_Startup()
EndFunc
; ==================== 坐标捕捉标签页 ====================
Func CreateCoordinateCaptureTab()
; 添加控件
$g_lblInfo = GUICtrlCreateLabel("点击按钮开始/停止坐标捕捉", 20, 50, 560, 20)
$g_btnCapture = GUICtrlCreateButton("开始捕捉", 250, 80, 100, 30)
GUICtrlSetOnEvent($g_btnCapture, "_ToggleCapture")
; 坐标显示区域
GUICtrlCreateGroup("实时鼠标位置", 20, 120, 560, 100)
$g_lblScreenPos = GUICtrlCreateLabel("屏幕坐标: (0, 0)", 30, 150, 540, 20)
$g_lblWindowPos = GUICtrlCreateLabel("窗口坐标: (0, 0)", 30, 180, 540, 20)
; 点击捕获的坐标信息区域
GUICtrlCreateGroup("捕获的坐标信息", 20, 230, 560, 250)
$g_lblCapturedScreenPos = GUICtrlCreateLabel("捕获的屏幕坐标: 未捕获", 30, 260, 540, 20)
GUICtrlSetColor($g_lblCapturedScreenPos, 0xFF0000) ; 红色
$g_lblCapturedWindowPos = GUICtrlCreateLabel("捕获的窗口坐标: 未捕获", 30, 290, 540, 20)
GUICtrlSetColor($g_lblCapturedWindowPos, 0x0000FF) ; 蓝色
$g_lblActiveWinInfo = GUICtrlCreateLabel("活动窗口信息: 无", 30, 320, 540, 140)
GUICtrlSetFont($g_lblActiveWinInfo, 9, 400, 0, "Arial")
GUICtrlSetColor($g_lblActiveWinInfo, 0x008000) ; 绿色
; 提示信息
GUICtrlCreateLabel("提示: 在捕捉模式下点击鼠标左键可捕获坐标", 20, 490, 560, 20)
EndFunc
; ==================== 智能点击器标签页 ====================
Func CreateAutoClickerTab()
GUISetFont(9, 400, 0, "Microsoft YaHei")
; ---- 顶部:模式选择 ----
GUICtrlCreateGroup("操作模式", 20, 50, 560, 60)
$g_radioNormal = GUICtrlCreateRadio("标准点击", 30, 70, 80, 20)
GUICtrlSetState($g_radioNormal, $GUI_CHECKED)
$g_radioDouble = GUICtrlCreateRadio("双击模式", 130, 70, 80, 20)
$g_radioInterval = GUICtrlCreateRadio("间隔点击", 230, 70, 80, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1)
; ---- 中部:公共设置 ----
GUICtrlCreateGroup("基本设置", 20, 120, 560, 120)
GUICtrlCreateLabel("目标位置:", 30, 145, 70, 20)
$g_lblPosition = GUICtrlCreateLabel("未设置 (按F2获取)", 110, 145, 200, 20)
GUICtrlSetColor($g_lblPosition, 0x660066)
GUICtrlCreateLabel("提示: 将鼠标移动到目标位置后按F2键获取坐标", 330, 145, 220, 20)
GUICtrlCreateGraphic(25, 175, 550, 1, $SS_ETCHEDHORZ)
GUICtrlCreateLabel("运行状态:", 30, 185, 70, 20)
$g_lblStatus = GUICtrlCreateLabel("等待开始操作", 110, 185, 400, 20)
GUICtrlSetColor($g_lblStatus, 0xFF3333)
GUICtrlCreateGroup("", -99, -99, 1, 1)
; ---- 下部:所有参数面板 ----
; 标准模式参数
GUICtrlCreateGroup("标准点击参数", 20, 250, 270, 150)
GUICtrlCreateLabel("点击延迟:", 30, 275, 70, 20)
$g_hNormalDelay = GUICtrlCreateInput($g_iNormalDelay, 110, 275, 80, 20)
Local $updownNormal = GUICtrlCreateUpdown($g_hNormalDelay)
GUICtrlSetLimit($updownNormal, 5000, 10)
GUICtrlCreateLabel("毫秒", 195, 275, 40, 20)
GUICtrlCreateLabel("点击次数:", 30, 305, 70, 20)
$g_hNormalTimes = GUICtrlCreateInput($g_iNormalTimes, 110, 305, 80, 20)
Local $updownNormalTimes = GUICtrlCreateUpdown($g_hNormalTimes)
GUICtrlSetLimit($updownNormalTimes, 9999, 1)
$g_hNormalInfinite = GUICtrlCreateCheckbox("无限模式", 30, 335, 100, 20)
GUICtrlSetTip($g_hNormalInfinite, "启用后将忽略点击次数限制")
GUICtrlSetState($g_hNormalInfinite, $g_bNormalInfinite ? $GUI_CHECKED : $GUI_UNCHECKED)
GUICtrlSetOnEvent($g_hNormalInfinite, "UpdateInfiniteMode")
; 双击模式参数
GUICtrlCreateGroup("双击模式参数", 310, 250, 270, 150)
GUICtrlCreateLabel("点击延迟:", 320, 275, 70, 20)
$g_hDoubleClickDelay = GUICtrlCreateInput($g_iDoubleClickDelay, 400, 275, 80, 20)
Local $updownDoubleClick = GUICtrlCreateUpdown($g_hDoubleClickDelay)
GUICtrlSetLimit($updownDoubleClick, 5000, 10)
GUICtrlCreateLabel("毫秒", 485, 275, 40, 20)
GUICtrlCreateLabel("两次间隔:", 320, 305, 70, 20)
$g_hDoubleInterval = GUICtrlCreateInput($g_iDoubleInterval, 400, 305, 80, 20)
Local $updownDoubleInterval = GUICtrlCreateUpdown($g_hDoubleInterval)
GUICtrlSetLimit($updownDoubleInterval, 1000, 10)
GUICtrlCreateLabel("毫秒", 485, 305, 40, 20)
GUICtrlCreateLabel("点击次数:", 320, 335, 70, 20)
$g_hDoubleTimes = GUICtrlCreateInput($g_iDoubleTimes, 400, 335, 80, 20)
Local $updownDoubleTimes = GUICtrlCreateUpdown($g_hDoubleTimes)
GUICtrlSetLimit($updownDoubleTimes, 9999, 1)
$g_hDoubleInfinite = GUICtrlCreateCheckbox("无限模式", 320, 365, 100, 20)
GUICtrlSetTip($g_hDoubleInfinite, "启用后将忽略点击次数限制")
GUICtrlSetState($g_hDoubleInfinite, $g_bDoubleInfinite ? $GUI_CHECKED : $GUI_UNCHECKED)
GUICtrlSetOnEvent($g_hDoubleInfinite, "UpdateInfiniteMode")
; 间隔模式参数
GUICtrlCreateGroup("间隔点击参数", 20, 410, 270, 150)
GUICtrlCreateLabel("点击间隔:", 30, 435, 70, 20)
$g_hIntervalDelay = GUICtrlCreateInput($g_iIntervalDelay, 110, 435, 80, 20)
Local $updownInterval = GUICtrlCreateUpdown($g_hIntervalDelay)
GUICtrlSetLimit($updownInterval, 5000, 10)
GUICtrlCreateLabel("毫秒", 195, 435, 40, 20)
GUICtrlCreateLabel("点击次数:", 30, 465, 70, 20)
$g_hIntervalTimes = GUICtrlCreateInput($g_iIntervalTimes, 110, 465, 80, 20)
Local $updownTimes = GUICtrlCreateUpdown($g_hIntervalTimes)
GUICtrlSetLimit($updownTimes, 9999, 1)
$g_hIntervalInfinite = GUICtrlCreateCheckbox("无限模式", 30, 495, 100, 20)
GUICtrlSetTip($g_hIntervalInfinite, "启用后将忽略点击次数限制")
GUICtrlSetState($g_hIntervalInfinite, $g_bIntervalInfinite ? $GUI_CHECKED : $GUI_UNCHECKED)
GUICtrlSetOnEvent($g_hIntervalInfinite, "UpdateInfiniteMode")
; 其他设置
GUICtrlCreateGroup("==其他设置==", 310, 410, 270, 150)
GUICtrlCreateLabel("紧急停止:", 320, 435, 70, 20)
GUICtrlCreateLabel("Ctrl+Esc", 400, 435, 100, 20)
GUICtrlCreateLabel("开始/停止:", 320, 465, 70, 20)
GUICtrlCreateLabel("空格键", 400, 465, 100, 20)
GUICtrlCreateLabel("获取位置:", 320, 495, 70, 20)
GUICtrlCreateLabel("F2键", 400, 495, 100, 20)
; ---- 底部:操作按钮 ----
$g_btnStart = GUICtrlCreateButton("开始/停止监控 (空格键)", 20, 570, 560, 50)
GUICtrlSetFont($g_btnStart, 10, 800)
GUICtrlSetBkColor($g_btnStart, 0x4CAF50)
GUICtrlSetColor($g_btnStart, 0xFFFFFF)
GUICtrlSetTip($g_btnStart, "开始/停止监控 (空格键)")
GUICtrlSetOnEvent($g_btnStart, "ToggleMonitoring")
EndFunc
; ==================== 颜色拾取器标签页 ====================
Func CreateColorPickerTab()
; 添加颜色显示区域
$g_hColorDisplay = GUICtrlCreateLabel("", 20, 50, 260, 100, $SS_SUNKEN)
GUICtrlSetBkColor(-1, 0xFFFFFF)
; 添加HEX颜色输入
GUICtrlCreateLabel("HEX颜色:", 20, 160, 80, 20)
$g_idHexInput = GUICtrlCreateInput("#FFFFFF", 75, 160, 100, 20)
GUICtrlSetOnEvent($g_idHexInput, "_HexInputChanged")
$g_idCopyHex = GUICtrlCreateButton("复制HEX", 185, 155, 80, 25)
GUICtrlSetOnEvent($g_idCopyHex, "_CopyHex")
; 添加RGB滑块
GUICtrlCreateLabel("红R:", 300, 55, 40, 20)
$g_idRedSlider = GUICtrlCreateSlider(320, 55, 200, 20, BitOR($TBS_NOTICKS, $TBS_TOOLTIPS))
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetOnEvent($g_idRedSlider, "_SliderChanged")
$g_idRedValue = GUICtrlCreateInput("255", 530, 55, 50, 20)
GUICtrlCreateLabel("绿G:", 300, 85, 40, 20)
$g_idGreenSlider = GUICtrlCreateSlider(320, 85, 200, 20, BitOR($TBS_NOTICKS, $TBS_TOOLTIPS))
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetOnEvent($g_idGreenSlider, "_SliderChanged")
$g_idGreenValue = GUICtrlCreateInput("255", 530, 85, 50, 20)
GUICtrlCreateLabel("蓝B:", 300, 115, 40, 20)
$g_idBlueSlider = GUICtrlCreateSlider(320, 115, 200, 20, BitOR($TBS_NOTICKS, $TBS_TOOLTIPS))
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetOnEvent($g_idBlueSlider, "_SliderChanged")
$g_idBlueValue = GUICtrlCreateInput("255", 530, 115, 50, 20)
; 添加RGB组合复制按钮
$g_idCopyRGB = GUICtrlCreateButton("复制RGB值", 500, 155, 80, 25)
GUICtrlSetOnEvent($g_idCopyRGB, "_CopyRGB")
; 添加屏幕取色按钮
$g_idPickColor = GUICtrlCreateButton("点击屏幕取色", 320, 155, 100, 25)
GUICtrlSetOnEvent($g_idPickColor, "_PickColor")
GUICtrlSetColor($g_idPickColor, 0xFF3333) ;文字红色
; 添加常用颜色区域 (36种颜色)
GUICtrlCreateLabel("常用颜色:", 20, 200, 80, 20)
Local $aCommonColors[36] = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF, _
0x000000, 0xFFFFFF, 0x808080, 0xC0C0C0, 0x800000, 0x808000, _
0x008000, 0x800080, 0x008080, 0x000080, 0xFFA500, 0xFFC0CB, _
0xFFD700, 0x4B0082, 0x006400, 0x8B4513, 0x708090, 0xD2B48C, _
0xFF6347, 0x7FFFD4, 0x9400D3, 0x9932CC, 0x8B0000, 0xE9967A, _
0x8FBC8F, 0x483D8B, 0x2F4F4F, 0x00CED1, 0x1E90FF, 0xFF1493]
; 创建6行x6列的颜色块 (36个)
For $i = 0 To 35
$g_idCommonColorBtns[$i] = GUICtrlCreateLabel("", 20 + Mod($i, 6) * 45, 220 + Int($i / 6) * 45, 40, 40, $SS_SUNKEN)
GUICtrlSetBkColor(-1, $aCommonColors[$i])
$g_aCommonColorValues[$i] = $aCommonColors[$i] ; 存储颜色值
GUICtrlSetCursor(-1, 0) ; 手型光标
GUICtrlSetOnEvent(-1, "_CommonColorClicked")
Next
EndFunc
; ==================== 坐标捕捉功能 ====================
Func _UpdateCoordinates()
Local $aMousePos = MouseGetPos()
GUICtrlSetData($g_lblScreenPos, "屏幕坐标: (" & $aMousePos[0] & ", " & $aMousePos[1] & ")")
; 获取活动窗口信息
Local $hActiveWin = _GetWindowUnderMouse()
If $hActiveWin <> $g_hLastActiveWin Then
$g_hLastActiveWin = $hActiveWin
$g_bFirstClick = True ; 窗口切换时重置首次点击标记
Local $sTitle = WinGetTitle($hActiveWin)
Local $aPos = WinGetPos($hActiveWin)
If Not [url=home.php?mod=space&uid=209627]@Error[/url] Then
GUICtrlSetData($g_lblActiveWinInfo, _
"活动窗口标题: " & $sTitle & @CRLF & _
"窗口位置: (" & $aPos[0] & ", " & $aPos[1] & ")" & @CRLF & _
"窗口大小: " & $aPos[2] & " × " & $aPos[3])
EndIf
EndIf
; 计算窗口相对坐标
If $hActiveWin Then
Local $aWinPos = WinGetPos($hActiveWin)
If Not @error Then
Local $iRelX = $aMousePos[0] - $aWinPos[0]
Local $iRelY = $aMousePos[1] - $aWinPos[1]
GUICtrlSetData($g_lblWindowPos, "窗口坐标: (" & $iRelX & ", " & $iRelY & ")")
EndIf
EndIf
EndFunc
Func _GetWindowUnderMouse()
Local $aMousePos = MouseGetPos()
Local $hWnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "long", $aMousePos[0], "long", $aMousePos[1])
If @error Then Return 0
; 如果是子窗口,尝试获取顶层父窗口
Local $hParent = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $hWnd[0], "uint", 2) ; GA_ROOT
If Not @error And $hParent[0] <> 0 Then Return $hParent[0]
Return $hWnd[0]
EndFunc
Func _ToggleCapture()
If $g_bCapturing Then
_StopCapture()
Else
_StartCapture()
EndIf
EndFunc
Func _StartCapture()
$g_bCapturing = True
$g_bFirstClick = True ; 重置首次点击标记
GUICtrlSetData($g_btnCapture, "停止捕捉")
GUICtrlSetData($g_lblInfo, "捕捉模式已激活 - 点击获取坐标")
; 设置鼠标钩子
$g_hHookProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
Local $hMod = DllCall("kernel32.dll", "handle", "GetModuleHandle", "ptr", 0)
$g_hHook = DllCall("user32.dll", "handle", "SetWindowsHookEx", _
"int", 14, _ ; $WH_MOUSE_LL
"ptr", DllCallbackGetPtr($g_hHookProc), _
"handle", $hMod[0], _
"dword", 0)
$g_hHook = $g_hHook[0]
EndFunc
Func _StopCapture()
$g_bCapturing = False
GUICtrlSetData($g_btnCapture, "开始捕捉")
GUICtrlSetData($g_lblInfo, "点击按钮开始/停止坐标捕捉")
_RemoveHook()
EndFunc
Func _MouseProc($nCode, $wParam, $lParam)
If $nCode < 0 Then
Return DllCall("user32.dll", "long", "CallNextHookEx", "handle", $g_hHook, "int", $nCode, "wparam", $wParam, "lparam", $lParam)[0]
EndIf
If $wParam = 0x0201 Then ; $WM_LBUTTONDOWN
; 首次点击时延迟一下确保窗口焦点更新
If $g_bFirstClick Then
Sleep(100)
$g_bFirstClick = False
EndIf
; 获取鼠标位置
Local $tMouse = DllStructCreate("int;int", $lParam)
Local $iX = DllStructGetData($tMouse, 1)
Local $iY = DllStructGetData($tMouse, 2)
; 获取精确的窗口句柄和位置
Local $hActiveWin = _GetWindowUnderMouse()
Local $sWinTitle = "无活动窗口"
Local $iRelX = 0, $iRelY = 0
Local $aWinPos[4] = [0, 0, 0, 0]
If $hActiveWin Then
$sWinTitle = WinGetTitle($hActiveWin)
; 使用更精确的GetWindowRect获取窗口位置
Local $tRect = DllStructCreate("long Left;long Top;long Right;long Bottom")
DllCall("user32.dll", "bool", "GetWindowRect", "hwnd", $hActiveWin, "ptr", DllStructGetPtr($tRect))
If Not @error Then
$aWinPos[0] = DllStructGetData($tRect, "Left")
$aWinPos[1] = DllStructGetData($tRect, "Top")
$iRelX = $iX - $aWinPos[0]
$iRelY = $iY - $aWinPos[1]
EndIf
EndIf
; 更新捕获的坐标信息
GUICtrlSetData($g_lblCapturedScreenPos, "捕获的屏幕坐标: (" & $iX & ", " & $iY & ")")
GUICtrlSetData($g_lblCapturedWindowPos, "捕获的窗口坐标: (" & $iRelX & ", " & $iRelY & ")")
GUICtrlSetData($g_lblActiveWinInfo, _
"活动窗口标题: " & $sWinTitle & @CRLF & _
"窗口位置: (" & $aWinPos[0] & ", " & $aWinPos[1] & ")" & @CRLF & _
"窗口大小: " & ($aWinPos[2] - $aWinPos[0]) & " × " & ($aWinPos[3] - $aWinPos[1]))
EndIf
Return DllCall("user32.dll", "long", "CallNextHookEx", "handle", $g_hHook, "int", $nCode, "wparam", $wParam, "lparam", $lParam)[0]
EndFunc
Func _RemoveHook()
If $g_hHook Then
DllCall("user32.dll", "bool", "UnhookWindowsHookEx", "handle", $g_hHook)
$g_hHook = 0
EndIf
If $g_hHookProc Then
DllCallbackFree($g_hHookProc)
$g_hHookProc = 0
EndIf
EndFunc
; ==================== 智能点击器功能 ====================
Func GetClickPosition()
Local $aPos = MouseGetPos()
$g_aClickPos[0] = $aPos[0]
$g_aClickPos[1] = $aPos[1]
GUICtrlSetData($g_lblPosition, "X:" & $aPos[0] & " Y:" & $aPos[1])
Local $hMarker = GUICreate("", 16, 16, $aPos[0]-8, $aPos[1]-8, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0xFF0000, $hMarker)
GUISetState(@SW_SHOW, $hMarker)
Sleep(300)
GUIDelete($hMarker)
EndFunc
Func ToggleMonitoring()
$g_bMonitoring = Not $g_bMonitoring
If $g_bMonitoring Then
If $g_aClickPos[0] = 0 And $g_aClickPos[1] = 0 Then
MsgBox(48, "错误", "请先设置点击位置!")
$g_bMonitoring = False
Return
EndIf
; 从控件读取当前参数值
$g_iNormalDelay = GUICtrlRead($g_hNormalDelay)
$g_iDoubleClickDelay = GUICtrlRead($g_hDoubleClickDelay)
$g_iDoubleInterval = GUICtrlRead($g_hDoubleInterval)
$g_iIntervalDelay = GUICtrlRead($g_hIntervalDelay)
; 读取点击次数
$g_iNormalTimes = GUICtrlRead($g_hNormalTimes)
$g_iDoubleTimes = GUICtrlRead($g_hDoubleTimes)
$g_iIntervalTimes = GUICtrlRead($g_hIntervalTimes)
$g_iClickCount = 0
$g_iLastClickTime = TimerInit()
GUICtrlSetData($g_btnStart, "■ 停止监控")
GUICtrlSetBkColor($g_btnStart, 0xF44336)
UpdateStatus()
Else
GUICtrlSetData($g_btnStart, "? 开始监控")
GUICtrlSetBkColor($g_btnStart, 0x4CAF50)
GUICtrlSetData($g_lblStatus, "已停止 (共点击 " & $g_iClickCount & " 次)")
EndIf
EndFunc
Func CheckAndClick()
Local $iCurrentMode = GetCurrentMode()
Local $iElapsed = TimerDiff($g_iLastClickTime)
Local $bInfinite = False
Local $iTargetTimes = 0
; 根据当前模式获取无限模式和目标次数
Switch $iCurrentMode
Case 1
$bInfinite = $g_bNormalInfinite
$iTargetTimes = $g_iNormalTimes
Case 2
$bInfinite = $g_bDoubleInfinite
$iTargetTimes = $g_iDoubleTimes
Case 3
$bInfinite = $g_bIntervalInfinite
$iTargetTimes = $g_iIntervalTimes
EndSwitch
; 检查是否达到点击次数限制
If Not $bInfinite And $g_iClickCount >= $iTargetTimes Then
ToggleMonitoring()
Return
EndIf
Switch $iCurrentMode
Case 1 ; 标准模式
If $iElapsed >= $g_iNormalDelay Then
MouseClick("left", $g_aClickPos[0], $g_aClickPos[1])
$g_iClickCount += 1
$g_iLastClickTime = TimerInit()
UpdateStatus()
EndIf
Case 2 ; 双击模式
If $iElapsed >= $g_iDoubleClickDelay Then
MouseClick("left", $g_aClickPos[0], $g_aClickPos[1])
Sleep($g_iDoubleInterval)
MouseClick("left", $g_aClickPos[0], $g_aClickPos[1])
$g_iClickCount += 2
$g_iLastClickTime = TimerInit()
UpdateStatus()
EndIf
Case 3 ; 间隔模式
If $iElapsed >= $g_iIntervalDelay Then
MouseClick("left", $g_aClickPos[0], $g_aClickPos[1])
$g_iClickCount += 1
$g_iLastClickTime = TimerInit()
UpdateStatus()
EndIf
EndSwitch
EndFunc
Func UpdateStatus()
Local $sMode = GetModeName(GetCurrentMode())
Local $sStatus = "??? "
Local $iTargetTimes = 0
Local $bInfinite = False
; 根据当前模式获取目标次数和无限模式状态
Switch GetCurrentMode()
Case 1
$iTargetTimes = $g_iNormalTimes
$bInfinite = $g_bNormalInfinite
Case 2
$iTargetTimes = $g_iDoubleTimes
$bInfinite = $g_bDoubleInfinite
Case 3
$iTargetTimes = $g_iIntervalTimes
$bInfinite = $g_bIntervalInfinite
EndSwitch
If $bInfinite Then
$sStatus &= "∞+" & $g_iClickCount
Else
$sStatus &= $g_iClickCount & "/" & $iTargetTimes
EndIf
$sStatus &= " | " & $sMode
If $bInfinite Then $sStatus &= " (无限)"
GUICtrlSetData($g_lblStatus, $sStatus)
EndFunc
Func GetCurrentMode()
If GUICtrlRead($g_radioNormal) = $GUI_CHECKED Then Return 1
If GUICtrlRead($g_radioDouble) = $GUI_CHECKED Then Return 2
If GUICtrlRead($g_radioInterval) = $GUI_CHECKED Then Return 3
Return 0
EndFunc
Func GetModeName($iMode)
Switch $iMode
Case 1
Return "标准"
Case 2
Return "双击"
Case 3
Return "间隔"
Case Else
Return "未知"
EndSwitch
EndFunc
Func EmergencyStop()
$g_bEmergencyStop = True
EndFunc
Func UpdateInfiniteMode()
$g_bNormalInfinite = (GUICtrlRead($g_hNormalInfinite) = $GUI_CHECKED)
$g_bDoubleInfinite = (GUICtrlRead($g_hDoubleInfinite) = $GUI_CHECKED)
$g_bIntervalInfinite = (GUICtrlRead($g_hIntervalInfinite) = $GUI_CHECKED)
GUICtrlSetState($g_hNormalTimes, $g_bNormalInfinite ? $GUI_DISABLE : $GUI_ENABLE)
GUICtrlSetState($g_hDoubleTimes, $g_bDoubleInfinite ? $GUI_DISABLE : $GUI_ENABLE)
GUICtrlSetState($g_hIntervalTimes, $g_bIntervalInfinite ? $GUI_DISABLE : $GUI_ENABLE)
UpdateStatus()
EndFunc
; ==================== 颜色拾取器功能 ====================
Func _UpdateColorDisplay($iColor)
GUICtrlSetBkColor($g_hColorDisplay, $iColor)
; 更新HEX值
Local $sHex = Hex($iColor, 6)
GUICtrlSetData($g_idHexInput, "#" & $sHex)
; 更新RGB滑块
Local $iRed = BitAND($iColor, 0xFF)
Local $iGreen = BitAND(BitShift($iColor, 8), 0xFF)
Local $iBlue = BitAND(BitShift($iColor, 16), 0xFF)
GUICtrlSetData($g_idRedSlider, $iRed)
GUICtrlSetData($g_idGreenSlider, $iGreen)
GUICtrlSetData($g_idBlueSlider, $iBlue)
GUICtrlSetData($g_idRedValue, $iRed)
GUICtrlSetData($g_idGreenValue, $iGreen)
GUICtrlSetData($g_idBlueValue, $iBlue)
EndFunc
; 滑块变化事件
Func _SliderChanged()
Local $iRed = GUICtrlRead($g_idRedSlider)
Local $iGreen = GUICtrlRead($g_idGreenSlider)
Local $iBlue = GUICtrlRead($g_idBlueSlider)
GUICtrlSetData($g_idRedValue, $iRed)
GUICtrlSetData($g_idGreenValue, $iGreen)
GUICtrlSetData($g_idBlueValue, $iBlue)
Local $iColor = BitOR(BitShift($iBlue, -16), BitShift($iGreen, -8), $iRed)
_UpdateColorDisplay($iColor)
EndFunc
; HEX输入变化事件
Func _HexInputChanged()
Local $sHex = GUICtrlRead($g_idHexInput)
$sHex = StringReplace($sHex, "#", "")
If StringLen($sHex) = 6 And StringIsXDigit($sHex) Then
Local $iColor = Dec($sHex)
_UpdateColorDisplay($iColor)
EndIf
EndFunc
; 屏幕取色
Func _PickColor()
ToolTip("请点击屏幕上任意位置选择颜色" & @CRLF & "按ESC取消", 0, 0)
While 1
If _IsPressed("1B") Then ; ESC键
ToolTip("")
Return
EndIf
If _IsPressed("01") Then ; 鼠标左键
Local $aPos = MouseGetPos()
Local $iColor = PixelGetColor($aPos[0], $aPos[1])
_UpdateColorDisplay($iColor)
ToolTip("")
Return
EndIf
Sleep(10)
WEnd
EndFunc
; 常用颜色点击事件
Func _CommonColorClicked()
Local $iIndex = -1
For $i = 0 To 35
If @GUI_CtrlId = $g_idCommonColorBtns[$i] Then
$iIndex = $i
ExitLoop
EndIf
Next
If $iIndex >= 0 Then
_UpdateColorDisplay($g_aCommonColorValues[$iIndex])
EndIf
EndFunc
; 提取屏幕颜色
Func _ExtractScreenColors()
ToolTip("请选择屏幕区域(按住鼠标左键拖动)" & @CRLF & "按ESC取消", 0, 0)
Local $aStartPos, $aEndPos
Local $hBitmap, $hImage
While 1
If _IsPressed("1B") Then ; ESC键
ToolTip("")
Return
EndIf
If _IsPressed("01") Then ; 鼠标左键
$aStartPos = MouseGetPos()
While _IsPressed("01")
Sleep(10)
WEnd
$aEndPos = MouseGetPos()
ExitLoop
EndIf
Sleep(10)
WEnd
ToolTip("正在分析颜色...", 0, 0)
; 确保起点在左上方
Local $iLeft = _Min($aStartPos[0], $aEndPos[0])
Local $iTop = _Min($aStartPos[1], $aEndPos[1])
Local $iWidth = Abs($aEndPos[0] - $aStartPos[0])
Local $iHeight = Abs($aEndPos[1] - $aStartPos[1])
If $iWidth < 10 Or $iHeight < 10 Then
ToolTip("区域太小,请选择更大的区域", 0, 0)
Sleep(1500)
ToolTip("")
Return
EndIf
; 捕获屏幕区域
$hBitmap = _ScreenCapture_Capture("", $iLeft, $iTop, $iLeft + $iWidth, $iTop + $iHeight, False)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
; 获取主要颜色
Local $aColors = _GetDominantColors($hImage, 12) ; 获取12种主要颜色
; 更新常用颜色块 (前12个)
For $i = 0 To _Min(11, UBound($aColors) - 1)
GUICtrlSetBkColor($g_idCommonColorBtns[$i], $aColors[$i])
$g_aCommonColorValues[$i] = $aColors[$i] ; 更新存储的颜色值
Next
_GDIPlus_BitmapDispose($hImage)
_WinAPI_DeleteObject($hBitmap)
ToolTip("已提取" & UBound($aColors) & "种主要颜色", 0, 0)
Sleep(1500)
ToolTip("")
EndFunc
; 获取主要颜色函数
Func _GetDominantColors($hBitmap, $iColorCount = 12)
Local $aColors[0]
; 这里简化处理,实际应该使用更复杂的算法如中值切割等
; 这里仅作为示例,从图像中随机采样一些点
Local $iWidth = _GDIPlus_ImageGetWidth($hBitmap)
Local $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
; 采样200个点
Local $iSampleCount = 200
Local $aSampledColors[$iSampleCount]
For $i = 0 To $iSampleCount - 1
Local $iX = Random(0, $iWidth - 1, 1)
Local $iY = Random(0, $iHeight - 1, 1)
$aSampledColors[$i] = _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY)
Next
; 简单统计出现频率最高的颜色
Local $aColorStats[0][2]
For $i = 0 To UBound($aSampledColors) - 1
Local $bFound = False
For $j = 0 To UBound($aColorStats) - 1
If $aColorStats[$j][0] = $aSampledColors[$i] Then
$aColorStats[$j][1] += 1
$bFound = True
ExitLoop
EndIf
Next
If Not $bFound Then
ReDim $aColorStats[UBound($aColorStats) + 1][2]
$aColorStats[UBound($aColorStats) - 1][0] = $aSampledColors[$i]
$aColorStats[UBound($aColorStats) - 1][1] = 1
EndIf
Next
; 按频率排序
_ArraySort($aColorStats, 1, 0, 0, 1)
; 提取前$iColorCount种颜色
Local $iCount = _Min($iColorCount, UBound($aColorStats))
ReDim $aColors[$iCount]
For $i = 0 To $iCount - 1
$aColors[$i] = $aColorStats[$i][0]
Next
Return $aColors
EndFunc
; 复制功能
Func _CopyHex()
Local $sHex = GUICtrlRead($g_idHexInput)
If $sHex <> "" Then
ClipPut($sHex)
_ShowToolTip("已复制HEX: " & $sHex)
EndIf
EndFunc
Func _CopyRGB()
Local $iRed = GUICtrlRead($g_idRedValue)
Local $iGreen = GUICtrlRead($g_idGreenValue)
Local $iBlue = GUICtrlRead($g_idBlueValue)
Local $sRGB = $iRed & ", " & $iGreen & ", " & $iBlue
ClipPut($sRGB)
_ShowToolTip("已复制RGB值: " & $sRGB)
EndFunc
Func _ShowToolTip($sMsg)
ToolTip($sMsg, 0, 0, "", 0, 2)
Sleep(1000)
ToolTip("")
EndFunc
; ==================== 主程序 ====================
Func _Exit()
_RemoveHook()
_GDIPlus_Shutdown()
Exit
EndFunc
; 设置热键
HotKeySet("{F2}", "GetClickPosition")
HotKeySet("{SPACE}", "ToggleMonitoring")
HotKeySet("^{ESC}", "EmergencyStop")
CreateMainGUI()
; 主循环 - 实时更新坐标
While 1
_UpdateCoordinates()
If $g_bMonitoring Then
CheckAndClick()
EndIf
If $g_bEmergencyStop Then
$g_bMonitoring = False
$g_bEmergencyStop = False
GUICtrlSetData($g_lblStatus, "已紧急停止")
GUICtrlSetData($g_btnStart, "? 开始监控")
GUICtrlSetBkColor($g_btnStart, 0x4CAF50)
EndIf
Sleep(50)
WEnd