#include <GUIConstants.au3>
#include <Misc.au3>
; ================================================================================ =================
; This script is a color helper tool that scans a specific pixel in World of Warcraft
; and sends corresponding keystrokes based on the color detected.
; It includes a GUI for control and various sending methods for compatibility.
; ================================================================================ =================
; Constants for window detection and scanning
Global Const $WINDOW_STRING = "[TITLE:World of Warcraft]"
Global Const $SCAN_POSITION_X = 1 ; X coordinate of the pixel to scan
Global Const $SCAN_POSITION_Y = 1 ; Y coordinate of the pixel to scan
Global Const $SOUND_PAUSE = 500 ; Frequency for pause sound notification
Global Const $SOUND_RESUME = 1000 ; Frequency for resume sound notification
; Constants for different key sending methods
Global Const $SEND_METHOD_CONTROL = 1 ; Using ControlSend function
Global Const $SEND_METHOD_SEND = 2 ; Using Send function
Global Const $SEND_METHOD_KEYS = 3 ; Using direct keyboard input via DLL calls
; Global variables for program state and GUI elements
Global $pause = True ; Program starts in paused state
Global $guiHandle ; Main GUI window handle
Global $statusLabel ; Shows if program is running or paused
Global $colorLabel ; Shows current color being detected
Global $keyLabel ; Shows last key that was sent
Global $radioControl ; Radio button for ControlSend method
Global $radioSend ; Radio button for Send method
Global $radioKeys ; Radio button for direct keyboard input
Global $btnToggle ; Button to start/pause the program
Global $btnColor ; Button to check current color
Global $btnExit ; Button to exit program
Global $sendMethod = $SEND_METHOD_KEYS ; Default send method
Global $colorMap = _InitColorMap() ; Initialize color to key mapping
Global $dll ; Handle for user32.dll
Global $sliderDelay ; Slider for controlling delay between keypresses
Global $checkboxRandom ; Checkbox for enabling random delay
Global $minDelay = 100 ; Minimum delay between actions in milliseconds
Global $maxDelay = 130 ; Maximum delay (calculated based on minDelay if random is enabled)
; Set up hotkeys
HotKeySet("{DEL}", "_TogglePause") ; DEL key toggles pause/resume
HotKeySet("{INS}", "_ShowCurrentColor") ; INS key shows current color
; Initialize DLL and GUI
$dll = DllOpen("user32.dll")
_CreateGUI()
; Start main program loop
MainLoop()
; Creates and initializes the GUI window
Func _CreateGUI()
$guiHandle = GUICreate("Color Helper", 300, 240)
; Status indicators
GUICtrlCreateLabel("Status:", 10, 10)
$statusLabel = GUICtrlCreateLabel("Paused", 100, 10)
GUICtrlCreateLabel("Current Color:", 10, 40)
$colorLabel = GUICtrlCreateLabel("-", 100, 40, 180)
GUICtrlCreateLabel("Last Key:", 10, 70)
$keyLabel = GUICtrlCreateLabel("-", 100, 70)
; Create radio buttons for different send methods
Local $groupSend = GUICtrlCreateGroup("Send Method", 10, 95, 280, 50)
$radioControl = GUICtrlCreateRadio("ControlSend", 20, 115, 80, 20)
$radioSend = GUICtrlCreateRadio("Send", 110, 115, 80, 20)
$radioKeys = GUICtrlCreateRadio("Keys", 200, 115, 80, 20)
GUICtrlSetState($radioKeys, $GUI_CHECKED)
$sendMethod = $SEND_METHOD_KEYS
GUICtrlCreateGroup("", -99, -99, 1, 1)
; Create delay control elements
GUICtrlCreateGroup("Delay Settings", 10, 145, 280, 70)
GUICtrlCreateLabel("ms Delay:", 20, 165, 55, 20)
$sliderDelay = GUICtrlCreateSlider(80, 165, 150, 20)
GUICtrlSetLimit($sliderDelay, 500, 10)
GUICtrlSetData($sliderDelay, 100)
Global $labelDelayValue = GUICtrlCreateLabel("100", 235, 165, 40, 20)
$checkboxRandom = GUICtrlCreateCheckbox("Add random delay (+30%)", 20, 185, 140, 20)
GUICtrlSetState($checkboxRandom, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
; Create control buttons
$btnToggle = GUICtrlCreateButton("Start/Pause (DEL)", 10, 210, 100, 25)
$btnColor = GUICtrlCreateButton("Check Color (INS)", 120, 210, 100, 25)
$btnExit = GUICtrlCreateButton("Exit", 230, 210, 60, 25)
GUISetState(@SW_SHOW)
EndFunc
; Initializes the color-to-key mapping array
; Each entry contains a hex color code and its corresponding key to send
Func _InitColorMap()
Local $map[22][2] ; Increased size to accommodate all the colors and keys
; Original colors
$map[0][0] = "FF0000" ; Red -> Key 1
$map[0][1] = "1"
$map[1][0] = "00FF00" ; Green -> Key 2
$map[1][1] = "2"
$map[2][0] = "0000FF" ; Blue -> Key 3
$map[2][1] = "3"
$map[3][0] = "FFFF00" ; Yellow -> Key 4
$map[3][1] = "4"
$map[4][0] = "FF00FF" ; Magenta -> Key 5
$map[4][1] = "5"
$map[5][0] = "00FFFF" ; Cyan -> Key 6
$map[5][1] = "6"
$map[6][0] = "F5F5DC" ; Beige -> Key 7
$map[6][1] = "7"
$map[7][0] = "FF8000" ; Orange -> Key 8
$map[7][1] = "8"
$map[8][0] = "00FF80" ; Turquoise -> Key 9
$map[8][1] = "9"
$map[9][0] = "8000FF" ; Purple -> Key 0
$map[9][1] = "0"
; Additional keys
$map[10][0] = "CCCCCC" ; Light Gray -> Key z
$map[10][1] = "z"
$map[11][0] = "33B233" ; Light Green -> Key x
$map[11][1] = "x"
$map[12][0] = "993399" ; Violet -> Key c
$map[12][1] = "c"
; Shift modifier colors
$map[13][0] = "E61A1A" ; Dark Red -> Key S1
$map[13][1] = "S1"
$map[14][0] = "1AE61A" ; Dark Green -> Key S2
$map[14][1] = "S2"
$map[15][0] = "1A1AE6" ; Dark Blue -> Key S3
$map[15][1] = "S3"
$map[16][0] = "E6E61A" ; Dark Yellow -> Key S4
$map[16][1] = "S4"
; Function keys colors,
;WILL ONLY WORK WITH SENDKEYS
$map[17][0] = "808000" ; Olive -> Key F1
$map[17][1] = "{F1}"
$map[18][0] = "800080" ; Dark Magenta -> Key F2
$map[18][1] = "{F2}"
$map[19][0] = "008080" ; Teal -> Key F3
$map[19][1] = "{F3}"
$map[20][0] = "808080" ; Grayish -> Key F4
$map[20][1] = "{F4}"
; Backtick key and shift modifier
$map[21][0] = "#B3B3B3" ; Silver/Light Gray -> Key `
$map[21][1] = "`"
Return $map
EndFunc
; Main program loop that handles color detection and key sending
Func MainLoop()
Local $lastActionTime = 0
Local $nextDelay = Random(100, 250)
While 1
_CheckGUIEvents()
If WinActive($WINDOW_STRING) And Not $pause Then
Local $currentTime = TimerInit()
; Check if enough time has passed since last action
If $currentTime - $lastActionTime >= $nextDelay Then
; Get color at scan position and find corresponding key
Local $currentColor = Hex(PixelGetColor($SCAN_POSITION_X, $SCAN_POSITION_Y), 6)
Local $key = _GetKeyForColor($currentColor)
If $key Then
SendKeyToWin($key)
GUICtrlSetData($keyLabel, $key)
GUICtrlSetData($colorLabel, $currentColor)
$lastActionTime = $currentTime
_UpdateDelays()
$nextDelay = Random($minDelay, $maxDelay)
EndIf
EndIf
EndIf
Sleep(10) ; Prevent high CPU usage
WEnd
EndFunc
; Handles GUI events (button clicks, radio buttons, etc.)
Func _CheckGUIEvents()
Local $msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
_Exit()
Case $btnToggle
_TogglePause()
Case $btnColor
_ShowCurrentColor()
Case $btnExit
_Exit()
Case $radioControl
$sendMethod = $SEND_METHOD_CONTROL
Case $radioSend
$sendMethod = $SEND_METHOD_SEND
Case $radioKeys
$sendMethod = $SEND_METHOD_KEYS
Case $sliderDelay
$minDelay = GUICtrlRead($sliderDelay)
Case $checkboxRandom
_UpdateDelays()
EndSwitch
EndFunc
; Updates delay settings based on slider and random checkbox
Func _UpdateDelays()
$minDelay = GUICtrlRead($sliderDelay)
If BitAND(GUICtrlRead($checkboxRandom), $GUI_CHECKED) Then
$maxDelay = Int($minDelay * 1.3) ; Add 30% for maximum random delay
Else
$maxDelay = $minDelay ; No randomization
EndIf
EndFunc
; Finds the corresponding key for a given color from the color map
Func _GetKeyForColor($hexColor)
For $i = 0 To UBound($colorMap) - 1
If $colorMap[$i][0] = $hexColor Then
Return $colorMap[$i][1]
EndIf
Next
Return ""
EndFunc
; Sends a key to the window using the selected send method
Func SendKeyToWin($key)
Switch $sendMethod
Case $SEND_METHOD_CONTROL
ControlSend($WINDOW_STRING, "", "", $key, 1)
Case $SEND_METHOD_SEND
If WinActive($WINDOW_STRING) Then
Send($key)
EndIf
Case $SEND_METHOD_KEYS
If WinActive($WINDOW_STRING) Then
_SendKeys($key)
EndIf
EndSwitch
EndFunc
; Sends keys using direct keyboard input via DLL calls
Func _SendKeys($key)
Local $code = Asc($key)
DllCall($dll, "int", "keybd_event", "int", $code, "int", 0, "int", 0, "int", 0) ; Key down
Sleep(1)
DllCall($dll, "int", "keybd_event", "int", $code, "int", 0, "int", 2, "int", 0) ; Key up
EndFunc
; Toggles the pause state of the program
Func _TogglePause()
$pause = Not $pause
If $pause Then
Beep($SOUND_PAUSE, 100)
GUICtrlSetData($statusLabel, "Paused")
Else
Beep($SOUND_RESUME, 100)
GUICtrlSetData($statusLabel, "Active")
EndIf
EndFunc
; Shows the current color at the scan position
Func _ShowCurrentColor()
Local $color = PixelGetColor($SCAN_POSITION_X, $SCAN_POSITION_Y)
Local $hexColor = Hex($color, 6)
GUICtrlSetData($colorLabel, $hexColor)
EndFunc
; Cleans up and exits the program
Func _Exit()
GUIDelete($guiHandle)
DllClose($dll)
Exit
EndFunc