The Game Script Beta 1

Post gaming related scripts
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

The Game Script Beta 1

23 Feb 2018, 09:34

Hey everyone,

Here a little something I made. The code is still in beta and the autopot feature is not working.. yet. However most of the code is working and almost bugg free. 99% of the code is my own, and where I borrowed code I mentioned it. Most lines of code come with some form of comment/explenation
Naamloos.png
Naamloos.png (17.46 KiB) Viewed 2429 times
This tool can be used to map you're own key's and send them some application. However the main goal for it is to be used with games.

The script comes with some features but the most basic are:
AutoWalk.
AutoPot (not working, yet)
SpamKey.
Send a key at specific intervall.
Sequence key's.
A featured list-view key remapper, remap any keyboard mouse or joystic button.
A profile for each game added to the script.
The abillity to add you're own code to the script.

ToDo:
Add Steam support.
Finish the autopot feature
Check code for buggs, check for bad spelling and style
Add mouse over tooltip discption

Code: Select all

#NoEnv
#Persistent
#ErrorStdOut
#SingleInstance ignore
#NoTrayIcon
SetBatchLines, -1
SetTitleMatchMode, 3
SendMode, Input
SetKeyDelay, 90, 1
SetWorkingDir, %A_ScriptDir%
CoordMode, mouse, client 
CoordMode, Pixel, client

{	; ----------------------------------------------------- Script Functions ------------------------------------------------------

	; Monitor WM message in the script gui.
	MsgMonitor(wParam, lParam, msg, hWnd) {
		SetBatchLines -1
		SetControlDelay -1
		global CtrlClass
		static RectB:=0, RectR:=0
		
		if (Msg = Wm_MouseMove) {
			DetectHiddenWindows, on
			DetectHiddenText, on
			
			if (A_GuiControl && !InStr(A_GuiControl, "UpdInfo")) {
				MouseGetPos, , , , CtrlClass
				ControlFocus, % CtrlClass
			}
			
			;ToolTip % "Control Handle: " Format("0x{1:x}", hWnd) "`nMouse Delay: " A_MouseDelay "`nGui Control: " A_GuiControl "`nControl ClassName: " CtrlClass 
			if (hWnd = hBtnGuiMin || hWnd = hBtnGuiRld && RectB = 0) {
				RectB := 1
				ControlGetPos, BtnX, BtnY, BtnW, BtnH, % CtrlClass
				WinGetPos, gX, gY, gW, gH , ahk_id %hScriptGui%
					
				Gui, SelRec:+Lastfound +AlwaysOnTop -Caption +ToolWindow +hWndhSlectRec
				Gui, SelRec:Color, Black
				WinSet, TransColor, Black
				Gui, SelRec:Show, x%gX% y%gY% w%gW% h%gH% NA

				CreateGDIControls(hSlectRec, BtnW, BtnH, 0xd5780a) ; BGR
				DrawFocusRec(BtnX,BtnY, BtnW, BtnH, 1, hBrush)
			
			} else if (hWnd != hBtnGuiRld && RectB = 1) {
				Gui, SelRec:Destroy
				RectB := 0
				
			} else if (hWnd = hBtnGuiClose && RectR = 0) {
				RectR := 1
				ControlGetPos, BtnX, BtnY, BtnW, BtnH, % CtrlClass
				WinGetPos, gX, gY, gW, gH , ahk_id %hScriptGui%
				
				Gui, SelRec:+Lastfound +AlwaysOnTop -Caption +ToolWindow +hWndhSlectRec
				Gui, SelRec:Color, Black
				WinSet, TransColor, Black
				Gui, SelRec:Show, x%gX% y%gY% w%gW% h%gH% NA
		
				;CreateGDIControls(hSlectRec, BtnW, BtnH, 0x0000FF)
				CreateGDIControls(hSlectRec, BtnW, BtnH, 0x2212E7) ; 2635E7
				DrawFocusRec(BtnX,BtnY, BtnW, BtnH, 1, hBrush)
					
			} else if (hWnd != hBtnGuiClose && RectR = 1) {
				Gui, SelRec:Destroy
				RectR := 0
			}
		}
		if (Msg = Wm_DraggGui) {
			if (GetKeyState("Lbutton", "P") && A_GuiControl = "") {
				if (WinExist("AutoPot: Help") || WinExist("Set number of keys to send.")) {
					PostMessage, 0xA1, 2
					return
				} else if (WinExist("AutoPotSetup:")) {
					PostMessage, 0xA1, 2
					return
				}
				FadeInOut(hScriptGui, "On")
				PostMessage, 0xA1, 2
				KeyWait, Lbutton
				FadeInOut(hScriptGui, "Off")
			}
		}
		if (msg = Wm_LbuttonDown) {
			ClsNNPrevious := ClsNNCurrent
			MouseGetPos, , , , ClsNNCurrent
			CtrlIdPrev:=CtrlIdCurrent
			CtrlIdCurrent:=A_GuiControl
			ControlGetText, ctrlTxtPrev, %ClsNNPrevious%
			ControlFocus, %ClsNNCurrent%
			SendMessage, 0x1330, 5,, %ClsNNCurrent%, TheGameScript
			
			; Hide the profile delete button when clicking a second time somewhere in the Gui.
			If (ListOn = 1) {
				 if (PrfDel = "hide") {
					GuiControl, %PrfDel%, PrfDel
					ListOn := PrfDel := ""
					return
				}
				GuiControl, , ChkBxPrf, 0
				PrfDel:=ChkBxPrf < 1 ? "show" : "hide"
				return
			}
			; When function EditGetKey() is active and a click outside the active control is found, then default text is written back to it.
			if (InputThisCtrl = 1 || TmrInputActive = 1) {
				if (CtrlIdPrev = CtrlIdCurrent)
					Exit	; Exit because the left click was inside a active control.
				for g, a in eCtrls
				{
					if (g = "Hotkeys") {
						for i, vCtrliD in a {
							if(ctrlTxtPrev = "" && CtrlIdPrev = vCtrliD) {
								vCtrliD:=g:=a:=i:=GuiControl(vCtrliD, "Hotkey") 
								break
					}}}
					if (g = "SendKeys") {
						for i, vCtrliD in a {
							if(ctrlTxtPrev = "" && CtrlIdPrev = vCtrliD) {
								vCtrliD:=g:=a:=i:=GuiControl(vCtrliD, "SendKey") 
								break
					}}}
					if (g = "TimerTime") {
						for i, vCtrliD in a {
							if(ctrlTxtPrev = "" && CtrlIdPrev = vCtrliD) {
								vCtrliD:=g:=a:=i:=GuiControl(vCtrliD, "00:00") 
								break
					}}}
					if (!vCtrliD) {
						TmrInputActive:=InputThisCtrl:=0
						break
				}}
				return
			}
			; A click inside a edit control enables G-Lable accosiation to function name. The changes made by send will call function EditGetKey(). Accosiation is switched off.
			If (InputThisCtrl = 0 && InStr(CtrlIdCurrent, "Hotkey") || InStr(CtrlIdCurrent, "SndKey")) {
				InputThisCtrl := 1
				GuiControl +gEditGetKey, %CtrlIdCurrent%
				Send, ^a{bs}
				GuiControl -gEditGetKey, %CtrlIdCurrent%
				; Hotkey to prevent showing the Windows default contextmenu for edit contolls.
				Hotkey, IfWinExist, TheGameScript
				Hotkey, Rbutton Up, RbttnUp, On
				return
			} else if (InStr(CtrlIdCurrent, "Tmr")) {
				TmrInputActive := 1
				Send, ^a{bs}
				return
			}
	
			; Drag gui from anywhere inside it.
			if ((GetKeyState("Lbutton", "P") = 1) && (A_GuiControl = "" || A_GuiControl = "UpdInfo1")) {
				PostMessage, 0x5001
		}}
		if (Msg = Wm_MbuttonUp) {
			if (TguiZ = 1)
				Gui 1:-AlwaysOnTop
			
			hWnd := Format("0x{1:x}", hWnd)
			SetMouseDelay -1, SetKeyDelay -1, SetControlDelay, -1
			MouseGetPos, pX, pY, , 
			PixelGetColor, PxlClr, %pX%, %pY%, rgb
			MouseGetPos , , , WinhWnd, CLsNN
			WinGetTitle, title, ahk_id %WinhWnd%
			WinGetClass, class, ahk_id %WinhWnd%
			ControlGetText, CtrlTxt, %CLsNN%
			GuiControlGet, KbF, focus
			ControlGetPos , Ctrl_x, Ctrl_y, Ctrl_Width, Ctrl_Hight, , ahk_id %hWnd% ;, TheGameScript
			VarName := A_GuiControl
			GuiControlGet, ControlVarID, Name, %CLsNN%
			WinGet, ScriptGui_Style, Style, TheGameScript 
			WinGet, ScriptGui_StyleEx, ExStyle, TheGameScript 
			
			MsgBox, % ""
			.	"Mouse pos:`t" pX "x" pY "`n"
			.	"Colour:`t`t " PxlClr "`n"
			.	"Last ClassName:`t" ClsNNCurrent "`n`n"
			.	"WindowTitle:`t " title "`n"
			. 	"Window hWnd:`t " WinhWnd "`n"
			. 	"Window class:`t " class "`n" 
			.	"Script Gui Style:`t " ScriptGui_Style "`n"
			.	"Script Gui ExStyle:`t " ScriptGui_StyleEx "`n`n"
			.	"Control Class:`t " CLsNN "`n"
			.	"Variable Name:`t " ControlVarID  "`t " %ControlVarID%  "`n"
			.	"Control hWnd:`t " hWnd "`n"
			.	"Control Pos:`t " Ctrl_x " x " Ctrl_y "`n"
			.	"Control Size:`t w = " Ctrl_Width " h = " Ctrl_Hight "`n"
			.	"Control text:`t " CtrlTxt "`n`n"
			.	"Control with keyboard focus:`n" kbf "`n`n"
			;, , , 1
			
			IfMsgBox, Ok
				if (TguiZ = 1)
					Gui 1:+AlwaysOnTop
			return
			
			;SetTimer, TTremove, 10
			; Altunerative for pause.
			;KeyWait, Lbutton, D T5
			;ToolTip, , , , 1

			
			if (TguiZ = 1)
					Gui 1:+AlwaysOnTop
		}
		if (msg = Wm_IsPaused) {
			ExitApp
		}
	}
	CreateGDIControls(hWnd, w, h, clr) {
		hdc := DllCall("GetDC", "Ptr", hWnd )
		hRegion := DllCall("CreateRectRgn", "int", 0, "int", 0, "int", 0, "int", 0)
		hBrush := DllCall("CreateSolidBrush", "UInt", clr)
	}
	
	DrawFocusRec(pX, pY, pW, pH, pPxls, hBrush) {
		DllCall("SetRectRgn", "uint", hRegion, "int", pX, "int", pY, "int", pX+pW, "int", pY+pH )
		DllCall("FrameRgn", "Ptr", hDC, "Ptr", hRegion, "Ptr", hBrush, "int", pPxls, "int", pPxls )
		DeleteGDIControls(hBrush, hRegion, hdc)
	}
	
	DeleteGDIControls(hBrush, hRegion, hdc) {
		DllCall( "DeleteObject", "uint", hBrush)
		DllCall( "DeleteObject", "uint", hRegion)
		DllCall( "DeleteDC", "uint", hdc)
	}
	
	; Convert color code to hex or decimal.
	FormatColor(c, bgr=0) {
		i:=0
		if (InStr(c, "0x")) {
			if (bgr = 1) {
				setformat,IntegerFast, H
				c := (c&255) << 16 | c&65280 | c >> 16 ""
				SetFormat, IntegerFast, d
			}
			Loop, 3
				clr .= Format("{:u} ", "0x" SubStr(c, 7-i, 2)), i += 2
		} else {
			clr := "0x" clr
			loop, Parse, c, %a_space%
				clr .= Format("{:X}", A_LoopField)
		 }
		return clr
	}

	; Writes back the name of any keyboard, mouse or joystic button to a edit control.
	EditGetKey() {
		static ThisCtrlClssNN, InputOn, PrevCtrlClssNN
		SetBatchLines -1
		GuiControl -gEditGetKey, %A_GuiControl%
		MouseGetPos, , , , ThisCtrlClssNN
		PrevCtrlClssNN := ThisCtrlClssNN
		; Monitor for any key pressed down on the keyboard, Joystic or mouse.
		; The loop will break when the user clicked outside the active control.
		loop 
		{
			If (ThisCtrlClssNN = PrevCtrlClssNN) {
				if (ThisKey = "Lbutton") {
					keywait, Lbutton, T0.200
					GuiControl, ,%A_GuiControl%, %ThisKey%
			}}
			If (ThisCtrlClssNN != ClsNNCurrent || !WinActive("ahk_id" (hWndAutoPot = "" ? hScriptGui : hWndAutoPot))) {
				;ControlFocus, Button37
				Hotkey, IfWinExist, TheGameScript
				Hotkey, Rbutton Up, RbttnUp, Off
				MouseGetPos, , , Handle, , 2
				ThisCtrlClssNN := "", InputThisCtrl := 0
				if (Handle != hScriptGui) {
						for g, a in eCtrls {
							if (g = "Hotkeys") {
								for i, vCtrliD in a {
									if((CtrlIdCurrent = "" ? CtrlIdPrev : CtrlIdCurrent) = vCtrliD) {
										vCtrliD:=g:=a:=i:=GuiControl(vCtrliD, "Hotkey") 
										break
							}}}
							if (g = "SendKeys") {
								for i, vCtrliD in a {
									if((CtrlIdCurrent = "" ? CtrlIdPrev : CtrlIdCurrent) = vCtrliD) {
										vCtrliD:=g:=a:=i:=GuiControl(vCtrliD, "SendKey") 
										break
							}}}
							if (g = "TimerTime") {
								for i, vCtrliD in a {
									if((CtrlIdCurrent = "" ? CtrlIdPrev : CtrlIdCurrent) = vCtrliD) {
										vCtrliD:=g:=a:=i:=GuiControl(vCtrliD, "00:00")
										break
							}}}
							if (!vCtrliD) {
								break
						}}}
				break
			}
			For i, ThisKey in InputKeys {
				if GetKeyState(ThisKey, "P") {
					ThisCtrlClssNN :="", InputThisCtrl:=0
					If (!Instr(ThisKey, "Joy")) {
						GuiControl, ,%A_GuiControl%, %ThisKey%
					} else If (Instr(ThisKey, "Joy") && InStr(A_GuiControl, "Hotkey")) {
						GuiControl, ,%A_GuiControl%, %ThisKey%
					}
					KeyWait, %ThisKey%, T0.200
					;ControlFocus, Button37
					Hotkey, IfWinExist, TheGameScript
					Hotkey, Rbutton Up, RbttnUp, Off
					break
			}}
			sleep 10
			If (InputThisCtrl = 0)
				break
		}
		RbttnUp:
		Hotkey, IfWinExist, TheGameScript
		Hotkey, Rbutton Up, RbttnUp, Off
		return
	}

	; GuiControl is made a function.
	GuiControl(ControlID, P:="", cmd:="") {
		InStr(CtrlIdCurrent, "Tmr")
			GuiControl, %cmd%, %ControlID%, %P%
		return % ""
	}

	; Fade Gui in or out.
	FadeInOut(hWnd, Pdragg:="") {
		SetBatchLines -1
		static Transparency := 0
		if (Pdragg = "On") {
			Loop {
				If (A_TickCount >= WaitNextTick) {
					WaitNextTick := A_TickCount+5
					WinSet, Transparent, % Transparency -= 5, ahk_id %hWnd%
					If (Transparency <= 215)
						break
			}}
			return
		} else if (Pdragg = "Off") {
			Loop {
				If (A_TickCount >= WaitNextTick) {
					WaitNextTick := A_TickCount+5
					WinSet, Transparent, % Transparency += 5, ahk_id %hWnd%
					If (Transparency >= 255) {
						WinSet, Transparent, Off, ahk_id %hWnd%
						break
			}}}
			return
		}
		If (Transparency = 0) {
			Loop {
				If (A_TickCount >= WaitNextTick) {
					WaitNextTick := A_TickCount+25
					WinSet, Transparent, % Transparency += 15, ahk_id %hWnd%
					If (Transparency >= 250){
						WinSet, Transparent, Off, ahk_id %hWnd%
						break
			}}}
		} else {
			Loop {
				If (A_TickCount >= WaitNextTick) {
					WaitNextTick := A_TickCount+25
					WinSet, Transparent, % Transparency -= 15, ahk_id %hWnd%
					If (Transparency <= 1)
						break
			}}}
		return
	}

	; One central messagebox for user notifacations.
	MessageBox(Title, TxT) {
		uChoise = No
		; Skip shis on first call.
		if (WinExist(Title)) {
			MessageBoxButtonYes:
			uChoise = Yes
			MessageBoxGuiClose:
			MessageBoxGuiEscape:
			MessageBoxButtonNo:
			Gui MessageBox:destroy
			Gui 1:-Disabled
			Gui 1:Default
			Gui 1:+LastFound 
			WinActivate, TheGameScript
			return
		}
		; Create MsgBox Gui.
		If (WinExist("AutoPotSetup:")) {
			Gui MessageBox:+AlwaysOnTop +ToolWindow +LastFound +hWndhWndMsgBox
			Gui MessageBox:+OwnerAutoPot
			Gui AutoPot:+Disabled
		} else {
			Gui MessageBox:+AlwaysOnTop +ToolWindow +LastFound +hWndhWndMsgBox
			Gui MessageBox:+Owner1
			Gui 1:+Disabled
		}
		Gui MessageBox:Default
		Gui MessageBox:Font, s11 q5, Lucon
		Gui MessageBox:add, Progress, x-1 y-1 hWndhWndWhiteBackgrnd Background0xFFFFFF
		; Choose question or exclametionmark picture.
		Gui MessageBox:Add, Picture, % "xm +BackgroundTrans " ((InStr(Title, "Help")) < 1 ? "Icon2" : "Icon3"), %A_WinDir%\system32\user32.dll
		Gui MessageBox:Add, Text, x55 y12 hWndhWndTxT +BackgroundTrans,`n %TxT%`n`n
		; Yes/No or Ok buttons.
		if (InStr(Title, "AutoPot: Help")) {
			Gui MessageBox:Add, Button, w88 h27 gMessageBoxButtonYes, ok
		} else {
			Gui MessageBox:Add, Button, w88 h27, Yes
			Gui MessageBox:Add, Button, x+m yp wp h27, No
		}
		DllCall("AnimateWindow", "UInt", hWndMsgBox)
		WinSet, Transparent, 0, ahk_id %hWndMsgBox%
		Gui MessageBox:Show, Center, %Title%
		; Move/size msxbox Gui and controls.
		WinGetPos, , , Gui_w, Gui_h, ahk_id %hWndMsgBox%
		ControlGetPos, , , , Ctrl_h, static2, ahk_id %hWndMsgBox%
		GuiControl, Move, msctls_progress321, % "w" (Gui_w-4) "h" (Ctrl_h+12)
		ControlGetPos, , , , Ctrl_h, msctls_progress321, ahk_id %hWndMsgBox%
		GuiControl, Move, static1, % "y" (Ctrl_h-16)/2
		if (InStr(Title, "AutoPot:")) {
			GuiControl, Move, Button1, % "y" (Gui_h-61) "x" (Gui_W-101)
		} else {
			GuiControl, Move, Button1, % "y" (Gui_h-61) "x" (Gui_W-203) 
			GuiControl, Move, Button2, % "y" (Gui_h-61) "x" (Gui_W-101)
		}
		WinGetPos, Gui_X, Gui_Y, Gui_W, Gui_H , ahk_id %hScriptGui%
		WinGetPos, , , mBoxW, mBoxH, ahk_id %hWndMsgBox%, ,ahk_id %hScriptGui%
		WinMove,ahk_id %hWndMsgBox%, , % ((Gui_W/2)-(mBoxW/2)+Gui_X), % ((Gui_H/2)-(mBoxH/2)+Gui_Y)
		WinSet, redraw, ,%Title%
		WinSet, Transparent, off, ahk_id %hWndMsgBox%
		; Wait for Gui distroy and return choise.
		WinWaitClose, %Title%
		If (WinExist("AutoPotSetup:")) {
			Gui AutoPot:-Disabled
			Gui AutoPot:Default
			Gui AutoPot:+LastFound 
			WinActivate, AutoPotSetup:
		}
		return % uChoise
	}

	; Enable or Disable controls.
	ToggleControls(pChkBx, IsGuiReady=1) {
		ChkBox := {ChkBx1: ChkBx1, ChkBx2: ChkBx2, ChkBx3: ChkBx3, ChkBx4: ChkBx4, ChkBx5: ChkBx5, ChkBx6: ChkBx6, ChkBx7: ChkBx7, ChkBx8: ChkBx8}
		For ThisChkBx, IsValue in ChkBox {
			if (pChkBx = ThisChkBx) {
				Toggle := IsValue < 1 ? "Enable" : "Disable"
				If (ThisChkBx = "ChkBx1") {
					GuiControl, %Toggle%, HotkeyWalk
					GuiControl, %Toggle%, LbWalk
					GuiControl, Disable, ShftDown
				} else If (ThisChkBx = "ChkBx3" || ThisChkBx = "ChkBx4" || ThisChkBx = "ChkBx5" || ThisChkBx = "ChkBx6") {
					GuiControl, %Toggle%, % "TmrSndKey"A_Index-2
					GuiControl, %Toggle%, % "Tmr"A_Index-2
				} else If (ThisChkBx = "ChkBx7") {
					GuiControl, %Toggle%, HotkeySpam
					GuiControl, %Toggle%, SpamSndKey
				} else If (ThisChkBx = "ChkBx8") {
					For i, K in ["HotkeySeq1", "HotkeySeq2", "SndkeySeq1", "SndkeySeq2", "SndkeySeq3", "SndkeySeq4", "SndkeySeq5", "DDL2","SeqReset"]
						GuiControl, %Toggle%, % K
				}
				if (IsGuiReady = 1)
					break
		}}
		AddText()
		return
	}

	; Add default text to input boxes so they can hint there meaning.
	AddText(Reset=0) {
		if (Reset = 1) {
			for g, a in eCtrls {
				if (g = "Hotkeys") {
					for i, CtrliD in a {
						If (%CtrliD% != "Hotkey") {
							GuiControl(CtrliD, "Hotkey")
				}}}
				if (g = "SendKeys") {
					for i, CtrliD in a {
						If(%CtrliD% != "SendKey") {
							GuiControl(CtrliD, "SendKey")
			}}}}
			GuiControl, Choose, DDL2, 1
			return
		}
		for g, a in eCtrls {
			if (g = "Hotkeys") {
				for i, CtrliD in a {
					If(%CtrliD% = "") {
						GuiControl(CtrliD, "Hotkey")
			}}}
			if (g = "SendKeys") {
				for i, CtrliD in a {
					If(%CtrliD% = "") {
						GuiControl(CtrliD, "SendKey")
			}}}
			if (g = "TimerTime") {
				for i, CtrliD in a {
					If(%CtrliD% = "") {
						GuiControl(CtrliD, "00:00")
		}}}}
		return
	}

	; Use a hotkey for games using W, or Left mouse button down, to move around.
	AutoWalk(Key:="") {
		SetMouseDelay -1
		Static wDown, KeyState
		
		If (LbWalk != 1) {
			; Allow calling AutoWalk() with no parameters from any hotkey.
			If (Key = "")
				Key := A_ThisHotkey
			
			; When w isn't already down, when wDown = 0 or empty.
			If (!wDown) {
				; Autowalk will not start if the hotkey is held down longer than 250mls
				If (GetKeystate(Key, "p")) {
					KeyWait, %Key%, T0.25
					If (ErrorLevel) {
						KeyWait, %key%
						return
					}
				} else If (GetKeystate("w", "p")) {
					KeyWait, w, T0.25
					If (ErrorLevel) {
						SendEvent, w
						return
				}}
				settimer, ChkKeyState, 100
				SendEvent, {w down}
				wDown := 1
				return
			}
		
		; Checks if the hotkey, w or the left mouse button is down and when so, send w up to stop moving.
		ChkKeyState:
		If (StateH := GetKeyState(Key, "P")) (StateW := GetKeyState("w", "P")) (StateLb := GetKeyState("Lbutton" , "P")) {
			If ((StateH = 1), WaitRelease := key) || ((StateW = 1), WaitRelease := "w") || ((StateLb = 1), WaitRelease := "Lbutton") {
				settimer, ChkKeyState, off
				KeyWait %WaitRelease%
			}
			SendEvent, {w up}
			wDown := ""
		}
		return
		; Enable mouse autowalk for games using Lbutton down to "move".
		; Double click Lbutton will enable it. Optional, hold down
		; the left mouse button to send the Shift key down. Usefull for attacking.
		} Else If (LbWalk = 1) {
			keywait, Lbutton, T0.200
			If (!errorlevel) {
				keywait, Lbutton, D T0.200
				If (!errorlevel) {
					keywait, Lbutton
					KeyState := KeyState != "down" ? "down" : "up"
					SendEvent, {Lbutton %KeyState%}

				} else if (ErrorLevel) {	
					Send, {Lbutton up}
					KeyState = up
				}
			} else If (ErrorLevel) {
				keywait, Lbutton, T0.010
				If (ErrorLevel) {
					if (GetKeystate("Lbutton", "P") && ShftDown = 1 && KeyState = "down") {
						SendEvent, {Shift down}
						KeyWait, Lbutton
						SendEvent, {Shift up}{Lbutton down}
			}}}}
		return
	}

	; Use a hotkey to toggle any key. This is used by the listview remap feature.
	ToggleKey(tglkey1, tglkey2:="") {
		SendMode, Event
		static KeyState
		DtKey := "LControl" "LShift" "LAlt" "LWin" "RControl" "RShift" "RAlt" "RWin"
		KeyState := KeyState != "down" ? "down" : "up"
		KeyWait, %tglkey1%
		Send, {%tglkey2% %KeyState%}
		return
	}

	; Send a series of key's one by one from L to R or reversed.
	KeySequence(pKey1, pKey2, pKey3:="", pKey4:="", pKey5:="") {
		SetBatchLines -1
		; Create hotkey's that keeps track of the last used key in the sequence.
		If (!Key1 && !Key2) {
			For i, Key in [pKey1, pKey2, pKey3, pKey4 , pKey5] {
				Key%i% := Key
				If ((Key = "") || (Key = "SendKey"))
					break
				TotalInUse += 1
				HotKey, % "~" Format("vk{1:x}", GetKeyVK(Key)), TrackSeqPos
				sleep 10
		}}
		; Send key's from LEFT to RIGHT.
		If (InStr(A_ThisHotKey, HotkeySeq1)) {
			CurrentPos += 1
			If (CurrentPos > TotalInUse)
				CurrentPos := 1
			Key := Key%CurrentPos%
			SendEvent, {%Key% down}{%Key% up}
			KeyWait, % StrReplace(A_ThisHotKey, "~")
			return
		}
		; Send key's in reverse order.
		If (InStr(A_ThisHotKey, HotkeySeq2)) {
			CurrentPos -= 1
			If (CurrentPos <= 0)
				CurrentPos := TotalInUse
			Key := Key%CurrentPos%
			SendEvent, {%Key% down}{%Key% up}
			KeyWait, % StrReplace(A_ThisHotKey, "~")
			return
		}
		; If one of the key's in the sequence is physically pushed down. The script will here update to the new position number.
		TrackSeqPos:
		((GetKeyState(Key1, "P") = 1, CurrentPos = 1) || (GetKeyState(Key2, "P") = 1, CurrentPos = 2) || (GetKeyState(Key3, "P") = 1, CurrentPos = 3) || (GetKeyState(Key4, "P") = 1, CurrentPos = 4) || (GetKeyState(Key5, "P") = 1, CurrentPos = 5))
		return
	}

	; This function came straight from the ahk manual. The code is not mine!
	SystemCursor(OnOff=1) {
		static AndMask, XorMask, $, h_cursor
			,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
			, b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13   ; blank cursors
			, h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13   ; handles of default cursors
		
		if (OnOff = "Init" or OnOff = "I" or $ = "")       ; init when requested or at first call
		{
			$ = h                                          ; active default cursors
			VarSetCapacity( h_cursor,4444, 1 )
			VarSetCapacity( AndMask, 32*4, 0xFF )
			VarSetCapacity( XorMask, 32*4, 0 )
			system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
			StringSplit c, system_cursors, `,
			Loop %c0%
			{
				h_cursor := DllCall( "LoadCursor", "Ptr",0, "Ptr",c%A_Index% )
				h%A_Index% := DllCall( "CopyImage", "Ptr",h_cursor, "UInt",2, "Int",0, "Int",0, "UInt",0 )
				b%A_Index% := DllCall( "CreateCursor", "Ptr",0, "Int",0, "Int",0
					, "Int",32, "Int",32, "Ptr",&AndMask, "Ptr",&XorMask )
		}}
		if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
			$ = b  ; use blank cursors
		else
			$ = h  ; use the saved cursors

		Loop %c0%
		{
			h_cursor := DllCall( "CopyImage", "Ptr",%$%%A_Index%, "UInt",2, "Int",0, "Int",0, "UInt",0 )
			DllCall( "SetSystemCursor", "Ptr",h_cursor, "UInt",c%A_Index% )
		}
		return
	}

}

{	; -------------------------------------------- Script variable and array setup ---------------------------------------------

	Global hdc,hRegion,hBrush,Key1,Key2,Key3,Key4,Key5,CurrentPos,TotalInUse,ListOn,HotkeySeq1,HotkeySeq2,SeqKeysModKey,hWnd,hBtnGuiClose,hBtnGuiMin,hBtnGuiRld,hScriptGui,hWndTabs,hWndAutoPot,ClsNNPrevious,ClsNNCurrent,ctrlTxtPrev,CtrlIdCurrent,CtrlIdPrev,CurrentPosNr,TmrInputActive,PrfDel,InputThisCtrl:=0,LbWalk:=0,ChkBxPrf:=0,ShftDown:=0,ChkBx1:=0,ChkBx2:=0,ChkBx3:=0,ChkBx4:=0,ChkBx5:=0,ChkBx6:=0,ChkBx7:=0,ChkBx8:=0,ChkBxPot1:=0,ChkBxPot2:=0,ChkBxCursor:=0,tgl:=0,CursorToggleState:=0,ChkBxStartMenu:=0,TguiZ:=1,eCtrls:=Object(),Hotkeys:=Object(),SendKeys:=Object(),TimerTime:=Object(),InputKeys:=Object(),Wm_LbuttonUp:=0x202,Wm_LbuttonDown:=0x201,Wm_DraggGui:=0x5001,Wm_IsPaused:=0x5000,Wm_MbuttonUp:=0x208,Wm_CtlColorBtn:=0x135,Tcm_SetCurFocus:=0x1330,Ws_Caption:=0xC00000,Ws_Border:=0x800000,Ss_Icon:=0x03,Tcs_FlatButtond:=0x8,Wm_MouseMove:=0x200,Wm_CtlColorStatic:=0x138

	; Create Array's
	TimerTime:=["Tmr1", "Tmr2", "Tmr3", "Tmr4"], Hotkeys:=["HotkeyWalk", "ToggleKey1", "HotkeySpam", "HotkeySeq1", "HotkeySeq2", "RmpKeyHotkey"], SendKeys:=["ToggleKey2", "SpamSndKey", "SndkeySeq1", "SndkeySeq2", "SndkeySeq3", "SndkeySeq4", "SndkeySeq5", "TmrSndKey1", "TmrSndKey2", "TmrSndKey3", "TmrSndKey4", "RmpSndKey", "LvAddSecNdKey", "SndKeyPot1", "SndKeyPot2"], eCtrls["Hotkeys"] := Hotkeys, eCtrls["SendKeys"] := SendKeys, eCtrls["TimerTime"] := TimerTime
	InputKeys := ["LButton", "RButton", "MButton", "XButton1", "XButton2", "Numpad0", "Numpad1", "Numpad2", "Numpad3", "Numpad4", "Numpad5", "Numpad6", "Numpad7", "Numpad8", "Numpad9","Numpad10","NumpadEnter", "NumpadAdd", "NumpadSub","NumpadMult", "NumpadDev", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Left", "Right", "Up", "Down", "Home","End", "PgUp", "PgDn", "Del", "Ins", "Capslock", "Numlock", "PrintScreen", "Pause", "LControl", "RControl", "LAlt", "RAlt", "LShift","RShift", "LWin", "RWin", "AppsKey", "BackSpace", "space", "Tab", "Esc", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n","o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", ".", "/", "[", "]", "\", "'", ";", "` ","Joy1", "Joy2", "Joy3", "Joy4", "Joy5", "Joy6", "Joy7", "Joy8", "Joy9", "Joy10", "Joy11", "Joy12", "Joy13", "Joy14", "Joy15", "Joy16", "Joy17","Joy18", "Joy19", "Joy20", "Joy21", "Joy22", "Joy23", "Joy24", "Joy25", "Joy26", "Joy27", "Joy28", "Joy29", "Joy30","Joy31", "Joy32"]

	; Variables for folders and files.
	ActiveProfile:="Settings\ActiveProfile\",ClientProfiles:="Settings\ClientProfiles\",ConfigFile:=ActiveProfile "Settings.ini",UserCode :=ActiveProfile "UserCode.ahk",KeyMap:=ActiveProfile "KeyMap.ahk",gPadMap:=ActiveProfile "gPadMap.ahk"

	; Variables for script gui.
	WinTitle:="Drop game.exe here or use button New Game.",Gui_X:=Gui_Y:="Center",LaunchClient:="New Game",SpmKeySndFrq:=20,WaitNext:=TotalOn:=bBrdLess:=bAdmin:=RowsInList:=ChkBxPot1:=ChkBxPot2:=Off:=Row:=i:=0,SliderOne:=50,SliderTwo:=50,Sldr1:="+",Sldr2:="+",Tabnr:=On:=1,OmitChars:="`t`n`r",Lv_h:=42,Wm_Syscommand:=0x112,Wm_Activateapp:=0x1c,Sc_Restore:=0xf120,Sc_Minimize:=0xF020,Wm_Mousemove:=0x200,Wm_RbuttonDown:=0x204,Wm_RbuttonUp:=0x205,Wm_SysColorChange:=0x15,Cb_ShowDropDown:=0x14F,Cb_GetcurSel:=0x147,Lvs_Ex_AutoSizeColumns:="+LV0x10000000",Ws_TopMostEx:=0x8,Bs_Notify:=0x4000,LvBussy:=0
	AutoPotText = Always start the game in window mode, so the script can 'see' the pixels !`n`nTo Setup:`nClick button 'Launch Game' and click within the search area to get`n the colour to search for. You will hear a sound, indicating the script found it.`nThen click the upper left corner of the search area to get the first set of`n coordinates. Next click the lower right corner to get the next set.`n`nWhen both slider Checkboxes are enabled the same process will repeat !`nOnce you're done clicking, the On/Off checkbox will tick on.

	; Ini Read.
	Loop, parse, % FileOpen(ConfigFile, 0).read(), `n, `r [
	{	; i := AssigneVarNameTo-i , 												%i% := AssigneValueForVarNameIn-%i% , 							i := ResetVar-i
		i := SubStr(A_LoopField, 1, InStr(A_LoopField, "=")-1), %i% := SubStr(A_LoopField, InStr(A_LoopField, "=")+1), i := 0
	}
		
	; Timer Array's for script Gui.
	Timers:=Array(), Timer1:=Object(), Timer2:=Object(), Timer3:=Object(), Timer4:=Object(), Timer1:=["TmrSndKey1","Tmr1", "ChkBx3"], Timer2:=["TmrSndKey2","Tmr2", "ChkBx4"], Timer3:=["TmrSndKey3","Tmr3", "ChkBx5"],Timer4:=["TmrSndKey4","Tmr4", "ChkBx6"], Timers["Timer1"] := Timer1, Timers["Timer2"] := Timer2, Timers["Timer3"] := Timer3, Timers["Timer4"] := Timer4

	; Create list with client profiles for the DropDown list.
	Loop, Settings\ClientProfiles\*.*, 2
	{
		IniWrite, % A_Index, % ClientProfiles A_LoopFileName "\Settings.ini", ScriptGuiVars, CurrentPosNr
		ProfileList .= A_LoopFileName "`n|"
	}

	; Vaiables for showing info.
	InfoHkWalk:=HotkeyWalk,InfoSeqKeys1:=HotkeySeq1,InfoSeqKeys2:=HotkeySeq2,InfoSndkeySeq1:=SndkeySeq1,InfoSndkeySeq2:=SndkeySeq2,InfoSndkeySeq3:=SndkeySeq3,InfoSndkeySeq4:=SndkeySeq4,InfoSndkeySeq5:=SndkeySeq5,InfoSeqKeysModKey:=SeqKeysModKey,InfoHkSpam:=HotkeySpam, InfoSpamKeySnd:=SpamSndKey,InfoToggleKey1:=ToggleKey1,InfoToggleKey2:=ToggleKey2,InfoTmrSndKey1:=TmrSndKey1,InfoTmrSndKey2:=TmrSndKey2, InfoTmrSndKey3:=TmrSndKey3,InfoTmrSndKey4:=TmrSndKey4

	; When spamey is on. Assigning send ratio chosen by user to var InfoSndFrq.
	if (ChkBx7 = 1)
		InfoSndFrq := 1000 // SpmKeySndFrq

	; Restart Script with elevated pevilages.
	if (bAdmin = 1 && !A_IsAdmin) {
		Run *RunAs "%A_ScriptFullPath%"
		ExitApp
	}
	
	; Register messages.
	OnMessage(Wm_DraggGui, "MsgMonitor"),OnMessage(Wm_LbuttonDown, "MsgMonitor"),OnMessage(Wm_LbuttonUp, "MsgMonitor"),OnMessage(Wm_IsPaused, "MsgMonitor"),OnMessage(Wm_MbuttonUp, "MsgMonitor"),OnMessage(Wm_MouseMove, "MsgMonitor")
	;OnMessage(Wm_MouseMove, "ActiveFocusTracking")

}

{	; --------------------------------------------------- Tray Menu and Script GUI --------------------------------------------

	; SystemTray Menu
	Menu, Tray, UseErrorLevel, on
	Menu, Tray, NoStandard
	Menu Tray, Icon
	Menu, Tray, Icon, % IconFile := ClientApp != "" ? ClientApp : A_WinDir "\system32\DDORes.dll",  % IconNr := InStr(IconFile, "DDORes.dll") > 0 ? "26" : ""
	If (ErrorLevel) {
		Menu Tray, Icon, DDORes.dll, 26
		IconFile := A_WinDir "\system32\DDORes.dll"
	}
	
	Menu, Tray, Add, Stop all timers, StopTimers
	Menu, Tray, Add, Show recent executed lines, RunSelectionFromMenu
	Menu, Tray, Add, List global variables, RunSelectionFromMenu
	Menu, Tray, Add, List script Hotkeys, RunSelectionFromMenu
	Menu, Tray, Add, List key history, RunSelectionFromMenu
	Menu, Tray, Add
	if not InStr(WinTitle, "Drop game.exe here")
		Menu, Tray, Add, Quit %WinTitle%, ButtonQuitGame
	Menu, Tray, Add, Open client installation folder, ButtonOpenFolder
	Menu, Tray, Add, Reload Script, ReloadScript
	Menu, Tray, Add, Exit Script, GuiClose

	; Script Gui
	GUI +LastFound +hWndhScriptGui +OwnDialogs +AlwaysOnTop -%Ws_Caption% +%Ws_Border%
	GUI, Color, 0xCCCCCC, 0xf1f1f1

	GUI, Margin, 5, 5
	GUI, Font
	GUI, add, text, x195 y+10 w95, - The Game Script -
	GUI, Font, s6 Bold, Sika Text
	Gui Add, Text, x+35 yp-1 w22 h14 gReloadScript vReloadSaveScript hWndhBtnGuiRld +0x800200 +Center -Background, R
	GUI, Font, s11 q5, Sika Text
	Gui Add, Text, x+2 yp wp hp gMinimize hWndhBtnGuiMin +0x800200 +Center -Background, -
	GUI, Font, s6 q5, Sika Text
	Gui Add, Text, x+2 yp w22 h14 gGuiClose vBtnGuiClose hWndhBtnGuiClose +0x800200 +Center, X
	GUI, Font
	GUI, Font, s8 q5, Sika Text
	GUI, Add, Tab3, xm ym w394 h439 Choose%TabNr% gTabEvents vTabNr hWndhWndTabs +AltSubmit +Border -Theme
	, General|Features|Rewire Key's

	; Tab 1
	GUI, Tab, General
	GUI, Add, Groupbox, xm+5 ym+25 w384 r2 Section Center -Theme
	
	; Load client icon or script default.
	if (!InStr(IconFile, "DDORes.dll")) {
		Gui, Add, Picture, xm+10 ym+38 h32 w32 +%Ss_Icon% +AltSubmit +BackgroundTrans, %IconFile%
	} else {
		Gui, Add, Picture, xm+10 ym+38 h32 w32 +%Ss_Icon% +AltSubmit +BackgroundTrans icon26, DDORes.dll
	}

	GUI, Add, Checkbox, xp+359 yp-3 w16 h16 0x1020 vChkBxPrf gChkBxProfileListShow -TabStop
	GUI, Font
	GUI, Font, s8 q8 Bold, Sika Text
	GUI, Add, Button, y+1 w16 h16 hidden Center vPrfDel gDeleteClientProfile hWndhWndPrfDel
	GUI, Font
	GUI, Font, s8 Bold, Sika Text
	GUI, Add, Text, xs+40 ys+20 r1 w320 Center vWinTitle,%WinTitle%
	GUI, Font
	GUI, Font, s8 q5, Sika Text
	Gui , Add, DDL, x130 y53 w165 hidden Choose%CurrentPosNr% hWndhWndProfile gDDLGetSelected vDDL1, %ProfileList%|
	
	; Buttons
	GUI, Add, Groupbox, xm+5 y+10 w384 r6 -Theme
	GUI, Add, Button, xp+5 yp+15 w80 h30 Section Default gLaunchClient vLaunchClient, %LaunchClient%
	GUI, Add, Button, x+m w80 h30 Disabled vQuitGame, Quit Game
	GUI, Add, Button, xs w80 h30 Disabled vActivateGame, Activate Game
	GUI, Add, Button, x+m w80 h30 vResetScript, Reset Script
	GUI, Add, Button, xs w80 h30, Open Folder
	GUI, Add, Button, x+m w80 h30 vAddCode, Add your own
	GUI, Add, Checkbox, x+4 ys+2 h15 Checked%TguiZ% gChkBxGuiOnTop vTguiZ, Toggle always on top
	GUI, Add, Checkbox, h15 Checked%bAdmin% gChkBxElevate vbAdmin, Run script as Admim
	GUI, Add, Checkbox, h15 Checked%bBrdLess% gChkBxBrdLess vbBrdLess, Borderless Fullscreen
	GUI, Add, Checkbox, xp+m y+m h15 Checked%ChkBxCursor% gAltTabHotKey vChkBxCursor, Hide cursor
	GUI, Add, Checkbox, h15 Checked%ChkBxStartMenu% gDisableWindowsStartMenu vChkBxStartMenu, Disable Windows StartMenu
	
	; Script info
	GUI, Add, Groupbox, xm+5 y+13 r11.5 w384 center -Theme,
	GUI, add, text, xp+10 yp+20 w370 r8 section gUpdKeyInfo vUpdInfo1, % "Hotkey AutoWalk:`t" InfoHkWalk "`n"
	. 	"`nSequence Foreward:`t" InfoSeqKeys1 "`nSequence Backward:`t" InfoSeqKeys2 "`nModifier key:`t`t" SeqKeysModKey "`n"
	. 	"`nKey's in the sequence:`n" InfoSndkeySeq1 " " InfoSndkeySeq2 " " InfoSndkeySeq3 " " InfoSndkeySeq4 " " InfoSndkeySeq5
	GUI, add, text, xp+195 yp w175 h200 r7 gUpdKeyInfo vUpdInfo2, % "Hotkey Spamkey:`t" InfoHkSpam "`n"
	.	"Sending SpamKey:`t" InfoSpamKeySnd "`nSend speed:`t`t" InfoSndFrq " key's`n" 
	GUI, add, text, xs y+15 w140 r6 section vTmrSndKey, % "`nSendkey on interval:`nKey to send:`t " TmrSndKey1 "`n"
	.	"Key to send:`t " TmrSndKey2 "`nKey to send:`t " TmrSndKey3 "`nKey to send:`t " TmrSndKey4
	GUI, add, text, ys+13 w120 r5 vTmrTime,`nInterval: `t%Tmr1%`nInterval: `t%Tmr2%`nInterval: `t%Tmr3%`nInterval: `t%Tmr4%

	; Tab 2
	GUI, Tab, Features
	; AutoWalk.
	GUI, Add, Groupbox, xm+5 ym+25 w160 r4.5 Section Center -Theme, AutoWalk
	GUI, Add, Checkbox, xp+5 yp+15 h15 Checked%ChkBx1% gChkBx1 vChkBx1, On/Off
	GUI, Add, Checkbox, x+m h15 Checked%LbWalk% gChkBx1 vLbWalk, Hack``nSlah.
	GUI, Add, Checkbox, xs+5 yp+20 h15 w150 Disabled Checked%ShftDown% gChkBx1 vShftDown, LButton Attack. ;Mouse down to shift down.
	GUI, Add, Edit, xs+5 yp+20 w65 Limit1 Center vHotkeyWalk hWndTest, %HotkeyWalk%
	
	; AutoPot.
	GUI, Add, Groupbox, ys w219 r4.5 Section Center -Theme, AutoPot
	GUI, Add, Checkbox, xp+5 yp+15 h15 Section Checked%ChkBx2% gChkBx2 vChkBx2, On/Off
	GUI, Add, button, x+108 ys+m h21 gChkBx2 vBttnPot, Setup
	GUI, Add, Checkbox, xs y+m w43 h15 Checked%ChkBxPot1% vChkBxPot1 gChkBx2, Pot1
	Gui Add, Slider, x+3 h22 w165 vSliderOne gSliders +0x138 %Sldr1%Disabled, %SliderOne%
	GUI, Add, Checkbox, xs w43 h15 Checked%ChkBxPot2% vChkBxPot2 gChkBx2, Pot2
	Gui Add, Slider, x+3 h22 w165 vSliderTwo gSliders +0x138 %Sldr2%Disabled, %SliderTwo%
	
	; Timer 1 to 4.
	GUI, Add, Groupbox, xm+5 y+13 r5 w190 Section Center -Theme, Timers
	for g, a in Timers {	; For every 'group, array' in main array Timers.
		for i, k in a {			; For every indexed key, vaule of key (k) in array a.
			if (i = 1 && g = "Timer1") {
				GUI, Add, Edit, xp+5 yp+15 w65 Limit1 Center Section v%k%,% %k%
			} else if (i = 1 && g != "Timer1") {
				GUI, Add, Edit, xs y+m w65 Limit1 Center v%k%,% %k%
			} else if (i = 2) {
				GUI, Add, Edit, x+m w45 r2 t1 Limit5 Center WantTab Number -0x200000 gTimerFormat v%k%,% %k%
			} else if (i = 3) {
				GUI, Add, Checkbox, % "x+m h15 Checked" %k% " g" k " v" k, on/off
			}
		} ; Resize edit control so a tab wil act as a space.
		GuiControl, Move, Tmr%A_Index%, h21
	}
	
	; SpamKey.
	GUI, Add, Groupbox, x+15 ys-15 w189 r5 Section Center -Theme, SpamKey
	GUI, Add, Checkbox, xp+5 yp+15 h15 gChkBx7 vChkBx7 Checked%ChkBx7%, On/Off
	GUI, Add, button, x+11 yp h21, Change speed
	GUI, Add, Edit, xs+5 yp+35 w65 Limit1 Center vHotKeySpam, %HotKeySpam%
	GUI, Add, Edit, xs+5 y+m w65 Limit1 Center vSpamSndKey, %SpamSndKey%
	
	; SequenceKeys.
	GUI, Add, Groupbox, xm+5 y+13 r9.7 w384 Section Center 0x1 -Theme, SequenceKey's
	GUI, Add, Checkbox, xp+5 ys+15 h15 Section gChkBx8 vChkBx8 Checked%ChkBx8%, On/Off
	GUI, Add, Button, xp+332 h21 gChkBx8 vSeqReset, Reset
	GUI, Add, Text, xs yp+25 w70 section, Foreward: ; in sequence:
	GUI, Add, Edit, y+m w70 Center  vHotkeySeq1, %HotkeySeq1%
	GUI, Add, Text, ys w70, Backward:
	GUI, Add, Edit, y+m w70 Center  vHotkeySeq2, %HotkeySeq2%
	GUI, Add, DDL, x+M yp w90 r11 Choose%DDL2% AltSubmit hWndhWndModKey gDDLGetSelected vDDL2, Modifier key's||LControl|LAlt|LShift|LWin|AppsKey|RControl|RAlt|RShift|RWin|Rbutton|
	GUI, Add, Text,xs y+10,Keys in the sequence:
	Loop, 5 {
		if (A_Index = 1)
			GUI, Add, Edit, xs  w70 Section Center Limit1 vSndkeySeq%A_Index%, %SndkeySeq1%
		else if (A_Index > 1) 
			GUI, Add, Edit, % "x+0 ys w70 Center Limit1 vSndkeySeq"A_Index, % SndkeySeq%A_Index%
	}

	; Tab 3
	GUI, Tab, Rewire Key's
	GUI, Add, Groupbox, xm+5 ym+25 w384 h407 Section Center 0x1 -Theme,
	GUI, Add, Edit, xp+5 yp+15 w65 h23 Center Section -0x04 Limit1 vRmpKeyHotkey, Hotkey
	GUI, Add, Edit, xs y+m w65 h23 Center -0x04 Limit1  vRmpSndKey, SendKey
	GUI, Add, button, ys+m h24 w74, Add
	GUI, Add, button, xp-1 y+4 hp wp gPurgeList, PurgeList
	GUI, Add, Checkbox, ys gLvOptions vIsToggleKey, Toggle key.
	GUI, Add, Checkbox, xp y+m gLvOptions vMapHotkey, Key::Tokey 
	GUI, Add, Checkbox, xp y+m gLvOptions vBlockNative, Block original key.
	GUI, Add, Checkbox, ys section gLvOptions vSecNdKey, Add second key.
	GUI, Add, Edit, xs h23 w65 center limit1 Disabled  vLvAddSecNdKey
	GUI, Add, ListView, xm+10 y+15 w375 h%Lv_h% hWndhWndLV vReMapList gListViewEvents +Grid +NoSortHdr +Multi +E0x100000 %lvs_ex_autosizecolumns%, Hotkey's|SendKey's|Send 2nd|Toggle Key|ReMap Hotkey|Block

	; Loop. With each itiration the value of A_loopField is joint to ColNr (Col%i%) for colum 1-6. On each sixth itiration 
	; adding new row to the ListView and resetting variable 'i' to zero for the next 6 columns. With each new
	; row, variable 'row' increment by 1 until the last row is found. With the last row, all 6 columns are modified.
	i:=0
	if (RowData) {
		Loop, parse, % RowData, :
		{
			i += 1, Col%i%:= A_LoopField
			If (i = 1)
				Row += 1
			If (RowsInList = Row)
				LV_ModifyCol(i, "Text Center AutoHdr")
			If(i = 6)
				LV_Add("", Col1, Col2, Col3, Col4, Col5, Col6), i:=0
		}
		i:=Row:=0,Col1:=Col2:=Col3:=Col4:=Col5:=Col6:=""
	}
	; Add option +AltSubmit after listview is created. Prevents unwanted calls to the subroutine during listview creation.
	GuiControl, +AltSubmit, ReMapList 

	; Tell the Os the Gui is animated. This enables transparancy to be set before the window is shown.
	DllCall("AnimateWindow", "UInt", hScriptGui)
	WinSet, Transparent, 0, ahk_id %hScriptGui%

	; Center Gui on screen when X or Y is empty, or when it was dragged outside the dektop dimensions by 75% or more.
	if (!Gui_X || Gui_X <= -(Gui_W/1.33) || Gui_X >= A_ScreenWidth-(Gui_W/1.33) || !Gui_Y || Gui_Y <= -(Gui_H/1.33) || Gui_Y >= A_ScreenHeight-(Gui_H/1.33)) 
		GUI, Show, Center h448, TheGameScript
	else
		GUI, Show, x%Gui_X% y%Gui_Y% h448, TheGameScript

	; Disable controls currently in use.
	Loop 8 
		ToggleControls("ChkBx"A_Index,  A_Index < 8 ? 0 : 1)

	; Fade in user interface.
	FadeInOut(hScriptGui)

	; Command line parameter, it notifies old instance it can now close when a restart occurred.
	Loop %0%
		if (InStr(%A_Index%, "0x"))
			PostMessage, Wm_IsPaused,,,, % "ahk_id" %A_Index%

	; Shortcut key's group for script Gui only.
	GroupAdd, TheGameScript, ahk_id %hScriptGui%

	; Set script Gui 'always on top' to off, if needed.
	if (TguiZ = 0)
		Gui 1:-AlwaysOnTop
	
	; Setting value's back to ahk default.
	SetBatchLines 10
	SetControlDelay 10
	return 
}

{	; ----------------------------------------------------- Lables Main Block ----------------------------------------------------
	;  HotKey's for Script GUI
	#IfWinActive, ahk_group TheGameScript
	{
		^vk04C::ListLines			; Ctrl+L
		^Vk56::ListVars 			; Ctrl+V
		^VK48::ListHotkeys		; Ctrl+H
		^VK4B::KeyHistory		; Ctrl+K
	}
	
	; Exit or reload the scipt and remove unused variables from configuration file.
	GuiClose:
	Gui, SelRec:Destroy
	GuiEscape:
	ReloadScript:
	; Open configuration file in read only mode and return file content to parsing loop.
	ParseFile:
	Loop, parse, % FileOpen(ConfigFile, 0).read(), `n, `r
	{
		; Create section name variable 'SectionName'.
		if InStr(A_Loopfield, "[" ) {
			SectionName := StrReplace(A_Loopfield, "["), SectionName := StrReplace(SectionName, "]")
			Continue, ParseFile
		}
		; Purge empty variables from configuration file.
		If ((SubStr(A_LoopField, InStr(A_LoopField, "=")+1)) <= "               ")
			IniDelete, %ConfigFile%, %SectionName%, % SubStr(A_LoopField, 1, InStr(A_LoopField, "=")-1)
	}

	WinGetPos, Gui_X, Gui_Y, Gui_W, Gui_H , ahk_id %hScriptGui%
	IniWrite, %Gui_X%, %ConfigFile%, ScriptGuiVars, Gui_X
	IniWrite, %Gui_Y%, %ConfigFile%, ScriptGuiVars, Gui_Y
	IniWrite, %Gui_W%, %ConfigFile%, ScriptGuiVars, Gui_W
	IniWrite, %Gui_H%, %ConfigFile%, ScriptGuiVars, Gui_H
	IniWrite, %Tabnr%, %ConfigFile%, ScriptGuiVars, Tabnr

	; Reload script.
	if (InStr(A_ThisLabel, "Reload")) {
		Gui 1:+Owner +AlwaysOnTop
		Menu, Tray, NoIcon

		if (A_Guicontrol = "ReloadSaveScript") { 
			WinGetTitle, EditorTitle, ahk_exe SciTE.exe
			ControlSend, SciTeTabCtrl1, {Ctrl Down}s{Ctrl up}, %EditorTitle%
		}
		
		If (!A_IsCompiled) {
			Run, "%A_AhkPath%" /f "%A_ScriptFullPath%" %hScriptGui%
		} else {
			WinGet, ProcessID, pid, ahk_id %hScriptGui%
			; Get the executable name from the pid that is running this script.
			for i in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_Process WHERE Handle=" ProcessID)
				ScriptExeName := i.name
			; Signal to restart, by passing current Gui handle, to new instance.
			Run, %ScriptExeName% /f %hScriptGui% 
		}
		Pause, on
	}
	FadeInOut(hScriptGui)
	SystemCursor("On")
	exitapp

	UpdKeyInfo:
	GuiControl, Text, UpdInfo1, % "Hotkey AutoWalk:`t" InfoHkWalk "`n"
	.	"`nSequence Foreward:`t" InfoSeqKeys1 "`nSequence Backward:`t" InfoSeqKeys2 "`nModifier key:`t`t" SeqKeysModKey "`n"
	. 	"`nKey's in the sequence:`n" InfoSndkeySeq1 " " InfoSndkeySeq2 " " InfoSndkeySeq3 " " InfoSndkeySeq4 " " InfoSndkeySeq5
	GuiControl, Text, UpdInfo2, % "Hotkey Spamkey:`t" InfoHkSpam "`n"
	.	"Sending SpamKey:`t" InfoSpamKeySnd "`nSend speed:`t`t" InfoSndFrq " key's`n" 
	exit
	{	; ---------------------------------------- Lables for working with Script GUI ----------------------------------------

		; Send Gui to taskbar.
		Minimize:
		Gui, SelRec:Destroy
		WinMinimize, ahk_id %hScriptGui%
		return

		; Keeping track of the last active tab.
		TabEvents:
		GUI, submit, nohide
		return

		; Launch selected item from the GuiContext menu.
		RunSelectionFromMenu:
		If(A_ThisMenuItem = "Show recent executed lines") 
			ListLines
		else If(A_ThisMenuItem = "List global variables")
			ListVars
		else If(A_ThisMenuItem = "List script Hotkeys")
			ListHotkeys
		else If(A_ThisMenuItem = "List key history")
			KeyHistory
		return

		; Unhide/hide the DDL with client applications and the tiny profile delete button.
		ChkBxProfileListShow:
		GUI, Submit, NoHide
		PrfDel:=ChkBxPrf < 1 ? "hide" : "show"
		PostMessage, Cb_ShowDropDown, %ChkBxPrf%,,, ahk_id %hWndProfile%
		GuiControl, %PrfDel%, PrfDel
		ListOn := 1
		GUI, Submit, NoHide
		return

		; Confirm and delete client profile.
		DeleteClientProfile:
		GuiControl, , ChkBxPrf, % ChkBxPrf:=0
		GuiControl, hide, PrfDel
		If (MessageBox("DeleteProfile:", "`nDo you wish to remove all files for.`n"
		.						  "Client profile:`t" WinTitle) = "yes") {
			FileRemoveDir, % ClientProfiles RegExReplace(WinTitle, "[<>:%\\/|?*]"), 1
			FileDelete, %ActiveProfile%*.*
			gosub, ReloadScript
		}
		return

		; Set GUI always on top on/off.
		ChkBxGuiOnTop:
		GUI, submit, nohide
		tgl := TguiZ < 1 ? "-" : "+"
		Gui 1:%tgl%AlwaysOnTop
		IniWrite, %TguiZ%, %ConfigFile%, ScriptGuiVars, TguiZ
		return

		; Enable this when client window doesn't except input from script or is acting weird.
		ChkBxElevate: 
		GUI, submit, nohide
		GuiControl, , bAdmin, % bAdmin < 1 ? 1 : 0
		if(MessageBox("Change elevation level:","Because of windows security features.`n "
		.						 "You will need to restart the script manualy.`n`n " 
		.						 "Change script privileges ?") = "No")
			return
		else
			IniWrite, %bAdmin%, %ConfigFile%, ScriptGuiVars, bAdmin
		ExitApp

		; Set client window to borderless fullscreen. It doesn't modify the resolution used by the game engine though, it just enlarges the client window rectangle.
		ChkBxBrdLess:
		GUI, submit, nohide
		if (bBrdLess = 1)
			GuiControl, Enable, LockMouse

		WinSet, Style, -0xC00000, ahk_id %hWndClient%	; 0xC00000 = WS_CAPTION
		WinSet, Style, +0x800000, ahk_id %hWndClient%	; 0x800000 = WS_BORDER
		WinSet, ExStyle, -0x8, ahk_id %hWndClient%	; 0x8 = WS_EX_TOPMOST
		WinSet, ExStyle, -0x40000, ahk_id %hWndClient%	; 0x40000 = WS_EX_APPWINDOW

		WinMove, ahk_id %hWndClient%, ,0 ,0 , % A_ScreenWidth, % A_ScreenHeight
		WinSet, Redraw, ,ahk_id %hWndClient%
		IniWrite, %bBrdLess%, %ConfigFile%, ScriptGuiVars, bBrdLess
		return

		; Hotkey lable and Checkbox lable for hiding system cursor.
		AltTabHotKey:
		GUI, submit, nohide	
		if (A_ThisHotkey = "Pause" && ChkBxCursor = 1) {
			SystemCursor("Toggle"), CursorToggleState := CursorToggleState < 1 ? 1 : 0 ;  <--		TRUE when var is zero or empty.
			return																							 ; var > 1 ? 0 : 1     <--		FALSE when var is zero or empty.
		}

		if (A_ThisHotkey = "~Alt"){
			if(GetKeystate("Alt", "P")){
				Hotkey, ~Alt, AltTabHotKey, Off
				KeyWait, Tab, D, T3
				if (!ErrorLevel){
					KeyWait, Tab
					If (CursorToggleState = 1 && WinExist("Task Switching")) {
						CursorToggleState := 0, SystemCursor("On")
						MouseMove, 10, 10, 50, R
					}
					KeyWait, alt
					Hotkey, ~Alt, AltTabHotKey, On
				}
				if (ErrorLevel)
					Hotkey, ~Alt, AltTabHotKey, On
				if (TguiZ = 1)
					Gui 1:+AlwaysOnTop		
			}
			return
		}

		IniWrite, %ChkBxCursor%, %ConfigFile%, ScriptGuiVars, ChkBxCursor	
		Return

		DisableWindowsStartMenu:
		Gui, Submit, NoHide
		if (ChkBxStartMenu = 1) {
			Hotkey, Sc15B up, StartMenuOff, On	; LWin
			Hotkey, Sc15C up, StartMenuOff, On	; RWin
		} else {
			Hotkey, Sc15B up, StartMenuOff, Off
			Hotkey, Sc15C up, StartMenuOff, Off
		}
		IniWrite, % (ChkBxStartMenu = 1 ? 1 : A_Space), %ConfigFile%, ScriptGuiVars, ChkBxStartMenu
		return
	}
	{ ; --------------------------------------- Labels used by or belonging to buttons --------------------------------------

		; Setup new client application, start or activate it's window.
		LaunchClient:
		if (LaunchClient = "New Game") {
			FileSelectFile, ClientApp, M3, , ,*.exe
			if (ErrorLevel)
				Exit
			
			Loop, parse, % ClientApp, `n, `r
				A_Index <= 1 ? Path := A_LoopField : ExeFile := A_LoopField
			ClientApp := Path "\" ExeFile, LaunchClient := "Start Game"

			; Add a new game via drag/drop when the following conditions are met.
			; 1) The script is set to its default settings. 2) The executable is droped within the WindowTitle groupbox.
			GuiDropFiles:
			if (LaunchClient = "New Game" && A_GuiX > 11 && A_GuiX < 384 || A_GuiY > 31 && A_GuiY < 54) {
				Loop, parse, A_GuiEvent, `n, `r
					ClientApp := A_LoopField, LaunchClient := "Start Game", Path := SubStr(A_LoopField, 1, InStr(A_LoopField, "\", ,-1)-1), ExeFile := SubStr(A_LoopField, InStr(A_LoopField, "\", ,-1)+1)
			}
			IfNotExist, %A_ScriptDir%\Settings
			{
				FileCreateDir, %ActiveProfile%
				FileCreateDir, %ClientProfiles%
			}

			IniWrite, Start Game, %ConfigFile%, ScriptGuiVars, LaunchClient
			IniWrite, %ClientApp%, %ConfigFile%, ScriptGuiVars, ClientApp
			IniWrite, %Path%, %ConfigFile%, ScriptGuiVars, Path
			IniWrite, %Profilefolder%, %ConfigFile%, ScriptGuiVars, Profilefolder
			IniWrite, %ExeFile%, %ConfigFile%, ScriptGuiVars, ExeFile
			IniWrite, % WinTitle := "Ready to start: " . StrReplace(ExeFile, ".exe"), %ConfigFile%, ScriptGuiVars, WinTitle
			sleep, 200
			
			gosub, ReloadScript
			exit ; Don't have to return here.
		}
		if (TguiZ = 1)
			Gui 1:-AlwaysOnTop

		; Start or activate client application.
		IfWinNotExist, ahk_exe %ExeFile%
		{
			Run, %ClientApp%, %Path%, , ProcessID
			WinWait, ahk_exe %ExeFile%, , , TheGameScript
			WinGet, HwndClient, ID, ahk_exe %ExeFile%
		}
		else IfWinExist, ahk_exe %ExeFile% 
		{
			WinGet, hWndClient, ID, ahk_exe %ExeFile%, , TheGameScript
			WinGet, ProcessID, PID, ahk_exe %ExeFile%, , TheGameScript
			WinRestore, ahk_id %hWndClient%
			WinActivate, ahk_id %hWndClient%, ,TheGameScript
		}

		; Checks for any popup window and wait for it to close.
		WinGetClass, ClientGuiClass, ahk_exe %ExeFile%, , TheGameScript		
		if InStr(ClientGuiClass, "Splash"){
			WinWaitClose, ahk_class %ClientGuiClass%, , , TheGameScript
			WinGetClass, ClientGuiClass, ahk_exe %ExeFile%, , TheGameScript
		}

		; Change button state
		GuiControl, Disable, LaunchClient
		GuiControl, Enable, QuitGame
		GuiControl, Enable, ActivateGame

		; Enable hotkey's where needed.		
		if (ChkBx1 = 1 && !instr(HotkeyWalk, "Hotkey"))
			Hotkey, ~%HotkeyWalk%, AutoWalk, On

		if (ChkBx2 = 1) {
			if (ChkBxPot1 = 1)
				Hotkey, %HotkeyPot1%, ToggleAutoPot, On
			if (ChkBxPot2 = 1)
				Hotkey, %HotkeyPot2%, ToggleAutoPot, On
		}

		Loop, 4 {
			ChkBx := "ChkBx"A_Index + 2
			if(%ChkBx% = 1) {
				Hotkey, ~!%A_index%, Alt%A_Index%, on
				Hotkey, !s, AltS, on
		}}

		if (ChkBx7 = 1)
			Hotkey, ~%HotkeySpam%, SpamKey, On

		if (ChkBx8 = 1 && !instr(HotkeySeq1, "Hotkey")) {
			if ((HotkeySeq2 = "" || HotkeySeq2 = "Hotkey") && (HotkeySeq1 != "")) {
				if (SeqKeysModKey) {
					Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, On
				} else {
					Hotkey, ~%HotkeySeq1%, SequenceKeys, On
				}
			} Else if (HotkeySeq2 != "" && HotkeySeq1 != "") {
				if (SeqKeysModKey) {
					if (HotkeySeq2 = "Hotkey") {
						Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, On
					} else {
						Hotkey, ~%SeqKeysModKey% & %HotkeySeq2%, SequenceKeys, On
						Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, On
					}
				} else {
					Hotkey, ~%HotkeySeq1%, SequenceKeys, On
					Hotkey, ~%HotkeySeq2%, SequenceKeys, On
		}}}

		if (bBrdLess = 1) {
			WinSet, AlwaysOnTop, Off, ahk_id %hWndClient%
			WinSet, Style, -0xC00000, ahk_id %hWndClient%    ; Remove caption from client window. 0xC00000 = WS_CAPTION
			WinSet, Style, +0x800000, ahk_id %hWndClient%    ; Apply a thin border around window edges. 0x800000 = WS_BORDER
			; Move window to upper left corner and set client rectangle to destop size.
			WinMove, ahk_id %hWndClient%, ,0 ,0 , %A_ScreenWidth%, %A_ScreenHeight%
			;WinMove, ahk_id %hWndClient%, ,%WinX% ,%WinY% ,	%WinWidth%, %WinHeight%
			WinSet, Redraw, ,ahk_id %hWndClient%
		}

		if(ChkBxCursor = 1)
			Hotkey, pause, AltTabHotKey, On

		; Create window group, which is used by the #IfWin* directive.
		GroupAdd, ClientGroup, ahk_id %hWndClient%
		GroupAdd, ClientGroup, ahk_class %ClientGuiClass%

		; Create's Client profile folder for new added games.
		; Refresh profile order in the puldown menu.
		if (InStr(WinTitle, "Ready to start: ")) {
			WinGetTitle, WinTitle, ahk_class %ClientGuiClass%
			WinTitle := RegExReplace(WinTitle, "[<>:%\\/|?*]")
			GuiControl, , WinTitle, %WinTitle%
			IniWrite, % WinTitle, % ConfigFile, ScriptGuiVars, WinTitle
			; Add a directory when it's missing.
			if (!FileExist(ClientProfiles WinTitle)) {
				FileCreateDir, % ClientProfiles WinTitle
				sleep 10
				
				; Copy setting files from active profile, back to there save location.
				For i, v in [ConfigFile, UserCode, KeyMap]
					FileCopy, % v, % ClientProfiles WinTitle, 1
				
				; Write changed profile order and value's back to config files. Refresh.
				Loop, Settings\ClientProfiles\*.*, 2
					IniWrite, % A_Index, % ClientProfiles A_LoopFileName "\Settings.ini", ScriptGuiVars, CurrentPosNr
				;IniRead, ExeFile, % ClientProfiles SelectFromList "\Settings.ini", ScriptGuiVars, ExeFile
				IniRead, CurrentPosNr, % ClientProfiles WinTitle "\Settings.ini", ScriptGuiVars, CurrentPosNr
				IniWrite, % CurrentPosNr, % ConfigFile, ScriptGuiVars, CurrentPosNr
				Gui, Submit, NoHide
		}}

		; Thread for this lable, lable LaunchClient, will wait untill process is closed    .   .  . . ..
		Process, WaitCLose, %ProcessID%

		if(CursorToggleState = 1)
			SystemCursor("On"), CursorToggleState := 0

		if (TguiZ = 1)
			Gui 1:+AlwaysOnTop

		ProcessID := hWndClient := "" 
		GuiControl, Enable, LaunchClient
		GuiControl, Disable, ActivateGame
		GuiControl, Disable, QuitGame
		return

		; Quit client application. If WinClose fails, WinKIll will take effect and forcing client procces to terminate.
		ButtonQuitGame:
		WinClose, %WinTitle%
		WinWaitClose, %WinTitle%, , 30
		if (errorlevel)
			WinKill, %WinTitle%
		return

		; Activate client window if it was allready launched from script.
		ButtonActivateGame:
		WinGet, State, MinMax, ahk_exe %ExeFile%, , TheGameScript
		If (State = -1)
			PostMessage, WM_SYSCOMMAND, SC_RESTORE, , , ahk_id %hWndClient%
		Else
			WinActivate, ahk_exe %ExeFile%, , TheGameScript

		if (ChkBx1 = 1 && !instr(HotkeyWalk, "Hotkey"))
			Hotkey, ~%HotkeyWalk%, AutoWalk, On

		if (ChkBx2 = 1) {
			if (ChkBxPot1 = 1)
				Hotkey, %HotkeyPot1%, ToggleAutoPot, On
			if (ChkBxPot2 = 1)
				Hotkey, %HotkeyPot2%, ToggleAutoPot, On
		}

		Loop, 4 {
			ChkBx := "ChkBx"A_Index + 2
			if(%ChkBx% = 1) {
				Hotkey, ~!%A_index%, Alt%A_Index%, on
				Hotkey, !s, AltS, on
		}}

		if (ChkBx7 = 1)
			Hotkey, ~%HotkeySpam%, SpamKey, On

		if (ChkBx8 = 1 && !instr(HotkeySeq1, "Hotkey")) {
			if ((HotkeySeq2 = "" || HotkeySeq2 = "Hotkey") && (HotkeySeq1 != "")) {
				if (SeqKeysModKey) {
					Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, On
				} else {
					Hotkey, ~%HotkeySeq1%, SequenceKeys, On
				}
			} Else if (HotkeySeq2 != "" && HotkeySeq1 != "") {
				if (SeqKeysModKey) {
					if (HotkeySeq2 = "Hotkey") {
						Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, On
					} else {
						Hotkey, ~%SeqKeysModKey% & %HotkeySeq2%, SequenceKeys, On
						Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, On
					}
				} else {
					Hotkey, ~%HotkeySeq1%, SequenceKeys, On
					Hotkey, ~%HotkeySeq2%, SequenceKeys, On
		}}}

		if (bBrdLess = 1) {
			WinSet, AlwaysOnTop, Off, ahk_id %hWndClient%
			WinSet, Style, -0xC00000, ahk_id %hWndClient%    ; Remove caption from client window. 0xC00000 = WS_CAPTION
			WinSet, Style, +0x800000, ahk_id %hWndClient%    ; Apply a thin border around window edges. 0x800000 = WS_BORDER
			WinMove, ahk_id %hWndClient%, ,%WinX% ,%WinY% ,	%WinWidth%, %WinHeight%   ; Move window to upper left corner and set client rectangle to destop size.
			WinSet, Redraw, ,ahk_id %hWndClient%
		}

		if(ChkBxCursor = 1)
			Hotkey, pause, AltTabHotKey, On 
		return

		ButtonResetScript:
		GuiControl, Text, WinTitle, Drop game.exe here or use button New Game.
		If (!InStr(WinTitle, "Drop game.exe here")) {
			;if (!FileExist(ClientProfiles WinTitle))
				;FileCreateDir, % ClientProfiles WinTitle
			For i, v in [ConfigFile, UserCode, KeyMap]
				FileCopy, % v, % ClientProfiles WinTitle, 1
		}
		FileDelete, %ActiveProfile%*.*
		gosub, ReloadScript
		return
		 
		; Open client installation directory in windows explorer.
		ButtonOpenFolder:
		Run, Explorer.exe "%Path%"
		Return

		; Change amount of keys to send each second. Minimum = 4, Maximum = 100
		ButtonChangeSpeed:
		GUI, Submit, NoHide
		If WinExist("Set number of keys to send.") {
			SpmKeySndFrq := RTrim(StrReplace(A_GuiControl, "Ms"))
			GuiControl, , SpmKeySndFrq, % 1000 // SpmKeySndFrq
			InfoSndFrq := 1000 // SpmKeySndFrq
			return
		}

		Gui SetSpamRatio:+Owner1 +LastFound +hWndhWndGuiSpam
		Gui 1:+Disabled
		GUI, SetSpamRatio:Font, s10 q5, Sika Text
		GUI, SetSpamRatio:Add, Text, xm ym, The current send ratio is approximately %A_Space%
		GUI, SetSpamRatio:Font, s10 q5 bold, Sika Text
		GUI, SetSpamRatio:Add, Text, x+2 yp w26 Center vSpmKeySndFrq, % 1000 // SpmKeySndFrq
		GUI, SetSpamRatio:Font
		GUI, SetSpamRatio:Font, s10 q5, Sika Text
		GUI, SetSpamRatio:Add, Text, x+2 yp,  %A_Space% key's a second.
		GUI, SetSpamRatio:Add, Text, xm y+10 Section, Change the period to wait between sending key's:

		Chk1:=Chk2:=Chk3:=Chk4:=Chk5:=Chk6:=Chk7:=0,((SpmKeySndFrq = 5), Chk1 = 1) || ((SpmKeySndFrq = 10), Chk2 = 1) || ((SpmKeySndFrq = 13), Chk3 = 1) || ((SpmKeySndFrq = 20), Chk4 = 1) || ((SpmKeySndFrq = 40), Chk5 = 1) || ((SpmKeySndFrq = 100), Chk6 = 1) || ((SpmKeySndFrq = 250), Chk7 = 1)

		GUI, SetSpamRatio:Add, Radio, xm w60 h23 Checked%Chk1% gButtonChangeSpeed, 5 Ms
		GUI, SetSpamRatio:Add, Radio, x+m wp h23 Checked%Chk2% gButtonChangeSpeed, 10 Ms
		GUI, SetSpamRatio:Add, Radio, x+m wp h23 Checked%Chk3% gButtonChangeSpeed, 13 Ms
		GUI, SetSpamRatio:Add, Radio, x+m wp h23 Checked%Chk4% gButtonChangeSpeed, 20 Ms
		GUI, SetSpamRatio:Add, Radio, x+m wp h23 Checked%Chk5% gButtonChangeSpeed, 40 Ms
		GUI, SetSpamRatio:Add, Radio, x+m wp h23 Checked%Chk6% gButtonChangeSpeed, 100 Ms
		GUI, SetSpamRatio:Add, Radio, x+m wp h23 Checked%Chk7% gButtonChangeSpeed, 250 Ms
		GUI, SetSpamRatio:Add, Button, xm y+m Default, Confirm
		DllCall("AnimateWindow", "UInt", hWndGuiSpam)
		WinSet, Transparent, 0, ahk_id %hWndGuiSpam%
		Gui SetSpamRatio:Show, Center, Set number of keys to send.
		WinGetPos, Gui_X, Gui_Y, Gui_W, Gui_H , ahk_id %hScriptGui%
		WinGetPos, , , gW, gH, ahk_id %hWndGuiSpam%, ,ahk_id %hScriptGui%
		WinMove,ahk_id %hWndGuiSpam%, , % ((Gui_W/2)-(gW/2)+Gui_X), % ((Gui_H/2)-(gH/2)+Gui_Y)
		WinSet, Transparent, off, ahk_id %hWndGuiSpam%
		WinWaitClose, Set number of keys to send.
		GuiControl, Text, KeySndFrq, % " Send " 1000 // SpmKeySndFrq " key's"
		gosub, UpdKeyInfo
		return

		; Save send interval.
		SetSpamRatioButtonConfirm:
		IniWrite, %SpmKeySndFrq%, %ConfigFile%, ScriptGuiVars, SpmKeySndFrq
		SetSpamRatioGuiEscape:
		SetSpamRatioGuiClose:
		Gui SetSpamRatio:destroy
		Gui 1:-Disabled
		WinActivate ahk_id %hScriptGui%
		return

		; Add code to the script. Using eighter the script it self, you're default editor or setup a text editor of you're choosing.
		ButtonAddYourOwn:
		if (TguiZ = 1)
			Gui 1:-AlwaysOnTop
		if (!DefaultEditor) {
			RegRead, DefaultEditor, HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command
			
			if (ErrorLevel) {
				if(MessageBox("Editor: Missing default editor.", "It seems you're machine hase no default editor installed.`n"
				.						  "Do you wish to select a text editor to edit .ahk files. Any text editor will do.`n"
				.						  "`nPress yes:`nWill setup a default editor. File association for .ahk will be installed.`n"
				.						  "`nPress no:`nWill enable the script to add code. Use no association for .ahk files.") = "yes"){
					FileSelectFile DefaultEditor, 2,, Select your editor, Programs (*.exe)
						if ErrorLevel
							return
					RegWrite REG_SZ, HKCR, AutoHotkeyScript\Shell\Edit\Command,, "%DefaultEditor%" "`%1"
				} else if(uChoise = "No"){
					DefaultEditor := uChoise
					IniWrite, % DefaultEditor := uChoise, %ConfigFile%, ScriptGuiVars, DefaultEditor
				}
			} else if (!ErrorLevel) {
				if(MessageBox("Editor: How to add code.", "A script editor is installed on you're machine.`n"
				.						  "Do you want to use it to add code, using #include, to the script?`n"
				.		   				  "`nYes to use you're default editor.`nNo will enable a editbox to add code.") = "No")
					DefaultEditor = no
				
				IniWrite, % StrReplace(DefaultEditor, """" `%1 """"), %ConfigFile%, ScriptGuiVars, DefaultEditor
		}}

		if (DefaultEditor = "no") {
			LineIndex := 5
			
			ifExist, %UserCode%
				Loop, read, %UserCode%
					EditCode .= A_LoopReadLine "`n", LineIndex += 1
			
			if (LineIndex >= 55)
				LineIndex := 55
			
			GUI, AddCode:+Owner1 +Resize
			Gui 1:+Disabled
			GUI AddCode:Font, s11
			Gui AddCode:Add, Edit, r%LineIndex% w700 +WantReturn 0x4 vEditCode
			Gui AddCode:Add, button, gExitEdit, Ok
			Gui AddCode:show, , Write you're own code here!
			GuiControl, AddCode:text, EditCode, %EditCode%
			return
				
			ExitEdit:
			Gui AddCode: submit, NoHide
			if (EditCode != "" && StrLen(EditCode) > 2)
				FileOpen(UserCode, "w").Write(EditCode)
			else if (StrLen(EditCode) <= 2)
				FileDelete, %UserCode%
			
			Gosub, ReloadScript
			Exit
					
			AddCodeGuiClose:
			AddCodeGuiEscape:
			LineIndex := EditCode := ""
			Gui AddCode:destroy
			Gui 1:-Disabled
			WinActivate, ahk_id %hScriptGui%
				
			if (TguiZ = 1)
				Gui 1:+AlwaysOnTop
			return
		}

		IfNotExist, %UserCode%
			FileAppend, ,%UserCode%
		RunWait, %DefaultEditor% %UserCode%
		hWndEditor := WinExist("A")
		WinGetTitle, Editor, ahk_id %hWndEditor%, , TheGameScript
		WinWaitClose, %Editor%
		if (TguiZ = 1)
			Gui 1:+AlwaysOnTop
		return

		; Add new remaped key's and settings info to the listview.
		ButtonAdd:
		Critical
		GUI, Submit, NoHide
		; Prevent adding empty or invalid key names to these edit controls 'RmpKeyHotkey' and 'RmpKeySend'
		if (!RmpKeyHotkey || !RmpSndKey || RmpKeyHotkey = "Hotkey" || RmpSndKey = "SendKey"){
			GuiControl, , RmpKeyHotkey, Hotkey
			GuiControl, , RmpSndKey, SendKey
			return
		}

		if (LvAddSecNdKey = "" || LvAddSecNdKey = "SendKey")
			LvAddSecNdKey := 0

		; Join keynames and options to variable 'RowData'. Delimeter between cells is a colon  ":".
		For i, CelDat in ColData := Array(RmpKeyHotkey, RmpSndKey, LvAddSecNdKey, IsToggleKey, MapHotkey, BlockNative) {
			RowData .= CelDat = 0 ? 0 ":" : ColData[i] ":"
		}
		i := 0

		; Add new row to the listview. Function LV_Add() Always returns the total-nr of rows in the list.
		RowsInList := LV_Add("", RmpKeyHotkey, RmpSndKey, LvAddSecNdKey, IsToggleKey, MapHotkey, BlockNative)
		Loop 6
			LV_ModifyCol(A_Index, "Text Center AutoHdr")

		; Write code for remaped key's to file. Which is later joinded to the script as none essential include file.
		if (LvAddSecNdKey ! integer)
			FileAppend, ~%RmpKeyHotkey%::`nSendEvent`, {%RmpSndKey% down}{%RmpSndKey% up}`nSendEvent`, {%LvAddSecNdKey% down}{%LvAddSecNdKey% up}`nKeyWait`, %RmpKeyHotkey%`nreturn`r`n, %KeyMap%
		else if (IsToggleKey = 1 && BlockNative = 1)
			FileAppend, %RmpKeyHotkey%::`nToggleKey`(`"%RmpKeyHotkey%`"`, `"%RmpSndKey%`"`)`nreturn`r`n, %KeyMap%
		else if(IsToggleKey = 1)
			FileAppend, ~%RmpKeyHotkey%::`nToggleKey`(`"%RmpKeyHotkey%`"`, `"%RmpSndKey%`"`)`nreturn`r`n, %KeyMap%
		else if(MapHotkey = 1 && BlockNative = 1)
			FileAppend, %RmpKeyHotkey%::%RmpSndKey%`n, %KeyMap%
		else if(MapHotkey = 1)
			FileAppend, ~%RmpKeyHotkey%::%RmpSndKey%`nreturn`r`n, %KeyMap%
		else if(BlockNative = 1)
			FileAppend, %RmpKeyHotkey%::`nSendEvent`, {%RmpSndKey% down}{%RmpSndKey% up}`nKeyWait`, %RmpKeyHotkey%`nreturn`r`n, %KeyMap%
		else
			FileAppend, ~%RmpKeyHotkey%::`nSendEvent`, {%RmpSndKey% down}{%RmpSndKey% up}`nKeyWait`, %RmpKeyHotkey%`nreturn`r`n, %KeyMap%

		; Resize listview hight to fit the newly added row.
		If(Lv_h >= 42 && RowsInList < 19) {
			Lv_h += 17
			GuiControl, move, ReMapList, h%Lv_h%
			IniWrite, %Lv_h%, %ConfigFile%, ListViewConfig, Lv_h
			GUI, submit, nohide
		}

		;Reset controls.
		GuiControl, , RmpKeyHotkey, Hotkey
		GuiControl, , RmpSndKey, SendKey
		GuiControl, , LvAddSecNdKey
		GuiControl, , SecNdKey, 0
		GuiControl, , IsToggleKey, 0
		GuiControl, , MapHotkey, 0
		GuiControl, , BlockNative, 0
		GuiControl, Disable, LvAddSecNdKey
		GuiControl, Enable, SecNdKey
		GuiControl, Enable, IsToggleKey
		GuiControl, Enable, MapHotkey
		GuiControl, Enable, BlockNative
		IniWrite, %RowsInList%, %ConfigFile%, ListViewConfig, RowsInList
		IniWrite, %RowData%, %ConfigFile%, ListViewConfig, RowData
		GUI, Submit, NoHide
		return

		LvOptions:
		GUI, Submit, NoHide
		; Toggle Gui controls for options on/off, depending on whatever feature is enabled.
		if (SecNdKey = 1) {
			GuiControl, Enable, LvAddSecNdKey
			GuiControl, Disable, IsToggleKey
			GuiControl, Disable, MapHotkey
			GuiControl, Disable, BlockNative
		} else if (SecNdKey = 0 && IsToggleKey= 0 && MapHotkey= 0 && BlockNative= 0) {
			GuiControl, Disable, LvAddSecNdKey
			GuiControl, Enable, IsToggleKey
			GuiControl, Enable, MapHotkey
			GuiControl, Enable, BlockNative
		}

		if(MapHotkey = 1) {
			GuiControl, Disable, SecNdKey
			GuiControl, Disable, IsToggleKey
		} else if(MapHotkey = 0 && SecNdKey = 0 && IsToggleKey= 0 && BlockNative= 0) {
			GuiControl, Enable, SecNdKey
			GuiControl, Enable, IsToggleKey
		} else if(MapHotkey = 0 && IsToggleKey = 0 && BlockNative= 1) {
			GuiControl, Enable, IsToggleKey
		}

		if(IsToggleKey = 1) {
			GuiControl, Disable, SecNdKey
			GuiControl, Disable, MapHotkey
		} else if(IsToggleKey = 0 && SecNdKey = 0 && MapHotkey = 0) {
			GuiControl, Enable, SecNdKey
			GuiControl, Enable, MapHotkey
		} else if(IsToggleKey = 0 && MapHotkey = 0 && BlockNative = 1) {
			GuiControl, Enable, MapHotkey
		}

		if(BlockNative = 1) {
			GuiControl, Disable, SecNdKey
		} else {
			GuiControl, Enable, SecNdKey
		}
		return

		; Remove old menu and, gets listview row number when clicked upon.
		ListViewEvents:
		if (A_GuiEvent = "Normal" || A_GuiEvent = "RightClick" && CtrlClass = "SysListView321") {
			menu, LVMenu, DeleteAll
			ActiveRowNr := A_EventInfo
		}
		return
	
		; ContextMenu for the ListView, or for somewhere else in the Gui.
		GuiContextMenu:
		if (A_GuiControl = "ReMapList" && CtrlClass = "SysListView321") {
			LV_GetText(RmpKeyHotkey, ActiveRowNr, 1), LV_GetText(BlockNative, ActiveRowNr, 6)
			BlockNative < 1 ? RmpKeyHotkey := "~" RmpKeyHotkey "::" : RmpKeyHotkey .= "::"
			menu, LVMenu, add, Delete hotkey:  %RmpKeyHotkey%, DeleteRow
			Menu, LVMenu, show, %A_GuiX%, %A_GuiY%
		} else if (A_GuiControl != "ReMapList") {
			menu, tray, show, %A_GuiX%, %A_GuiY%
		}
		return

		DeleteRow:
		SetBatchLines, -1
		Clipboard =
		RowsInList -= 1,ExludeMapping:=RmpKeyHotkey,LV_Delete(ActiveRowNr)
		If (Lv_h > 42 && RowsInList <= 17)
			Lv_h -= 17
		GuiControl, move, ReMapList, % "h" Lv_h
		Loop, parse, % RowData, :
		{ 
			; Find posittion of the row that was removed from the listview in variable 'RowData'.
			If (i < 7 && Row != ActiveRowNr) {
				i += 1
				If (i = 1)
					Row += 1
				If (i = 6)
					i := 0
				If (i = 1 && Row = ActiveRowNr)
					i := 6
			}
			; Join value's for all six collums in the removed row, to variable purge.
			If (Row = ActiveRowNr) {
				i -= 1, Purge .= A_LoopField ":"
				
				; Save sendkey to clipboard.
				If (i = 4)
					Clipboard = %A_LoopField%
				
				; Join sendkey to var ExludeMapping when double colon remaping is in use.
				If (i = 1 && A_LoopField = 1)
					ExludeMapping .= Clipboard
				
				; Remove the string to purge from variable 'RowData'
				If (i = 0) {
					RowData := StrReplace(RowData, Purge), i := Row := 0
					break
		}}}

		; Create variable for storing new file content and exclude removed lines from it.
		Loop, parse, % FileOpen(KeyMap, "r-rwd").Read(), `n,`r
		{
			if (A_LoopField != ExludeMapping && ExludeMapping != "return"){
				NewContent .= A_LoopField "`n"
			} else if (A_LoopField = ExludeMapping) {
				If (A_LoopField = "Return")
					ExludeMapping := ""
				else
					ExludeMapping := "Return"
		}}

		; Save changes.
		File:=FileOpen(KeyMap, "w").Write(NewContent).File.Close()
		if (RowsInList = 0) {
			RowsInList:=RowData:="",Lv_h:=42
			IniWrite, %A_Space%, %ConfigFile%, ListViewConfig, Lv_h
			FileDelete, %KeyMap%
		} else {
			IniWrite, %Lv_h%, %ConfigFile%, ListViewConfig, Lv_h
		}
		IniWrite, %RowsInList%, %ConfigFile%, ListViewConfig, RowsInList
		IniWrite, %RowData%, %ConfigFile%, ListViewConfig, RowData
		Row:=ActiveRowNr:=Purge:=NewContent:=File:=""
		return

		PurgeList:
		if(MessageBox("Purge Lisrtview:", "Do you really want remove all remaped key's ?") = "Yes"){
			LV_Delete()
			FileDelete, %KeyMap%
			GuiControl, move, ReMapList, h42
			IniWrite, % RowsInList := "", %ConfigFile%, ListViewConfig, RowsInList
			IniWrite, % RowData := "", %ConfigFile%, ListViewConfig, RowData
			IniWrite, % Lv_h := "", %ConfigFile%, ListViewConfig, Lv_h
			gosub, ReloadScript
			Exit
		}
		return
	}
	{	; -------------------------------------------- Lables used by checkboxes ---------------------------------------------

		; AutoWalk
		ChkBx1:
		GUI, submit, nohide
		if (A_GuiControl = "ShftDown" ) {
			IniWrite, %ShftDown%, %ConfigFile%, ScriptGuiVars, ShftDown
			return
		}

		if (A_GuiControl = "LbWalk" ) {
			if (LbWalk = 1) {
				GuiControl, , HotkeyWalk, Lbutton
				GuiControl, Enable, ShftDown
			} else if (LbWalk = 0) {
				GuiControl, , HotkeyWalk, Hotkey
				GuiControl, Disable, ShftDown
			}
			return
		}

		if (ChkBx1 = 1) {
			if (!HotkeyWalk || HotkeyWalk = "Hotkey") {
				GuiControl, , ChkBx1, 0
				return
			}
			Hotkey, ~%HotkeyWalk%, AutoWalk, On T1 B1
			InfoHkWalk:=HotkeyWalk
				
		} else if (ChkBx1 = 0) {
			Hotkey, ~%HotkeyWalk%, AutoWalk, off
			ShftDown:=LbWalk:=HotkeyWalk:=InfoHkWalk:=ChkBx1:=""
			GuiControl, , ShftDown, 0
			GuiControl, , LbWalk, 0
			GuiControl, , HotkeyWalk
		}

		For i, v in ["HotkeyWalk", "LbWalk", "ShftDown", "ChkBx1"]
			IniWrite, % %v%, %ConfigFile%, ScriptGuiVars, %v%
		i:=0,v:=""
		ToggleControls("ChkBx1")
		gosub, UpdKeyInfo
		return

		; Autopot.
		ChkBx2:
		GUI, Submit, NoHide
		if (ChkBx2 = 1 && !ChkBxPot1 && !ChkBxPot2) {
			GuiControl, ,ChkBx2, % ChkBx2 := 0
			return
		}

		if (A_GuiControl = "ChkBx2") {
			IniWrite, % (ChkBx2 = 1 ? 1 : ""), %ConfigFile%, ScriptGuiVars, ChkBx2
		} else if (A_GuiControl = "ChkBxPot1") {
			if (ChkBxPot1 = 0) {
				GuiControl, ,SliderOne, 50
				GuiControl, Disable, SliderOne
				
				For i, v in ["xTopRec1", "yTopRec1", "xBtmRec1", "ScriptGuiVars", "yBtmRec1", "wRec1", "hRec1", "SearchClr1", "HotkeyPot1"]
					IniWrite, % %Var% := "", %ConfigFile%, ScriptGuiVars, %Var%
				i:=0,v:=""
				
			} else {
				GuiControl, Enable, SliderOne
			}
			IniWrite, % (ChkBxPot1 = 1 ? 1 : ""), %ConfigFile%, ScriptGuiVars, ChkBxPot1
			IniWrite, % (ChkBxPot1 = 1 ? 50 : ""), %ConfigFile%, ScriptGuiVars, SliderOne
			IniWrite, % (ChkBxPot1 = 1 ?  "-" : ""), %ConfigFile%, ScriptGuiVars, Sldr1

		} else if (A_GuiControl = "ChkBxPot2") {
			if (ChkBxPot2 = 0) {
				GuiControl, ,SliderTwo, 50
				GuiControl, Disable, SliderTwo
				
				For i, v in ["xTopRec2", "yTopRec2", "xBtmRec2", "ScriptGuiVars", "yBtmRec2", "wRec2", "hRec2", "SearchClr2", "HotkeyPot2"]
					IniWrite, % %Var% := "", %ConfigFile%, ScriptGuiVars, %Var%
				i:=0,v:=""
				
			} else {
				GuiControl, Enable, SliderTwo
			}
			IniWrite, % (ChkBxPot2 = 0 ? "" : 1), %ConfigFile%, ScriptGuiVars, ChkBxPot2
			IniWrite, % (ChkBxPot2 = 0 ? "" : 50), %ConfigFile%, ScriptGuiVars, SliderTwo
			IniWrite, % (ChkBxPot2 = 0 ? "" : "-"), %ConfigFile%, ScriptGuiVars, Sldr2
		} else if (A_GuiControl = "BttnPot") {
			;CoordMode, Pixel, Window
			Gui AutoPot:+Owner1 +ToolWindow +LastFound hWndhWndAutoPot
			Gui 1:+Disabled
			Gui AutoPot:Default
			Gui AutoPot:add, text, y+m w80 section, Hotkey pot1:
			Gui AutoPot:add, Hotkey, y+m wp vHotkeyPot1, +1
			Gui AutoPot:add, edit, y+m wp vSndKeyPot1 Center, %SndKeyPot1%
			Gui AutoPot:add, text, ys wp, Hotkey pot2:
			Gui AutoPot:add, Hotkey, y+m wp vHotkeyPot2, +2
			Gui AutoPot:add, edit, y+m wp vSndKeyPot2 Center, %SndKeyPot2%
			; Colour variation scale is allowed by 50% of the total range.
			Gui AutoPot:add, text, xs w175, Set colour shading scale, search up to 50`% in colour tone difference.
			Gui AutoPot:add, slider, xs w80 Range0-125 ToolTip,
			Gui AutoPot:add, slider, x+m wp Range0-125 ToolTip,
			Gui AutoPot:add, Button, xs y+m w80 gActivateGame, Launch game
			Gui AutoPot:add, Button, x+m wp Default, Help
			DllCall("AnimateWindow", "UInt", hWndAutoPot)
			WinSet, Transparent, 0, ahk_id %hWndAutoPot%
			Gui AutoPot:Show, Center, AutoPotSetup:
			
			WinGetPos, Gui_X, Gui_Y, Gui_W, Gui_H , ahk_id %hScriptGui%
			WinGetPos, , , pw, ph, ahk_id %hWndAutoPot%, ,ahk_id %hScriptGui%
			WinMove, AutoPotSetup:, , % (Gui_W//2)-(pw//2)+Gui_X, % (Gui_H//2)-(ph//2)+Gui_Y
			
			for i, CtrliD in SendKeys
				if(InStr(CtrliD, "SndKeyPot"))
					GuiControl, ,%CtrliD%, SendKey
				
			WinSet, Transparent, Off, ahk_id %hWndAutoPot%
		}
		ToggleControls("ChkBx2")
		return

		AutoPotButtonHelp:
		Gui AutoPot:+Disabled
		MessageBox("AutoPot: Help", AutoPotText)
		return
			
		ActivateGame:
		GUI, Submit, NoHide
		CoordMode, mouse, client 
		CoordMode, pixel, client 
		WinActivate, ahk_id %hWndClient%, , TheGameScript
		WinRestore, ahk_id %hWndClient%, , TheGameScript

		if (!SearchClr1 && ChkBxPot1 = 1) {
			;Get colour
			KeyWait, Lbutton, D
			if (ErrorLevel = 0) {
				MouseGetPos, Px, Py
				PixelGetColor, SearchClr1, Px, Py, Alt Slow Rgb
				SoundPlay, C:\Windows\Media\ding.wav
			}
			
			; Top Left X-Y pos search area
			KeyWait, Lbutton
			KeyWait, Lbutton, D
			if (ErrorLevel = 0) {
				MouseGetPos, xTopRec1, yTopRec1
				SoundPlay, C:\Windows\Media\ding.wav
			}
			
			; Bottom Right X-Y pos search area
			KeyWait, Lbutton
			KeyWait, Lbutton, D
			if (ErrorLevel = 0) {
				MouseGetPos, xBtmRec1, yBtmRec1
				SoundPlay, C:\Windows\Media\ding.wav
			}
			
			wRec1 := xBtmRec1 - xTopRec1, hRec1 := yBtmRec1 - yTopRec1
			For i, v in ["xTopRec1", "yTopRec1", "xBtmRec1", "ScriptGuiVars", "yBtmRec1", "wRec1", "hRec1", "SearchClr1", "HotkeyPot1"]
				IniWrite, % %v%, %ConfigFile%, ScriptGuiVars, %v%
			i:=0,v:=""

			Hotkey, %HotkeyPot1%, ToggleAutoPot, On
		}	

		if (!SearchClr2 && ChkBxPot2 = 1) {
			KeyWait, Lbutton, D
			if (ErrorLevel = 0) {
				MouseGetPos, Px, Py
				PixelGetColor, SearchClr2, Px, Py, Alt Slow Rgb
				SoundPlay, C:\Windows\Media\ding.wav
			}
			
			KeyWait, Lbutton
			KeyWait, Lbutton, D
			if (ErrorLevel = 0) {
				MouseGetPos, xTopRec2, yTopRec2
				SoundPlay, C:\Windows\Media\ding.wav
			}
			
			KeyWait, Lbutton
			KeyWait, Lbutton, D
			if (ErrorLevel = 0) {
				MouseGetPos, xBtmRec2, yBtmRec2
				SoundPlay, C:\Windows\Media\ding.wav
			}
			
			wRec2 := xBtmRec2 - xTopRec2, hRec2 := yBtmRec2 - yTopRec2
			For i, v in ["xTopRec2", "yTopRec2", "xBtmRec2", "ScriptGuiVars", "yBtmRec2", "wRec2", "hRec2", "SearchClr2", "HotkeyPot2"]
				IniWrite, % %v%, %ConfigFile%, ScriptGuiVars, %v%
			i:=0,v:=""

			Hotkey, %HotkeyPot2%, ToggleAutoPot, On
		}
		GuiControl, , ChkBx2, 1
		IniWrite, 1, %ConfigFile%, ScriptGuiVars, ChkBx2
		hWndAutoPot := " "
		Gui AutoPot:destroy
		Gui 1:-Disabled
		hWndAutoPot := " "
		GUI, Submit, Nohide
		return

		AutoPotGuiClose:
		AutoPotGuiEscape:
		Gui AutoPot:destroy
		Gui 1:-Disabled
		hWndAutoPot := ""
		GUI, Submit, Nohide
		WinActivate, ahk_id %hScriptGui%

		if (TguiZ = 1)
			Gui 1:+AlwaysOnTop
		return

		Sliders:
		GUI, submit, nohide
		ThisSlider := A_GuiControl

		If (ThisSlider = "SliderOne"){
			if (ChkBxPot1 = 1) {
				IniWrite, % %ThisSlider%, %ConfigFile%, ScriptGuiVars, % ThisSlider
				IniWrite, % xBtmRec1 := (wRec1/100)*SliderOne, %ConfigFile%, ScriptGuiVars, xBtmRec1
				
			} else if (ChkBxPot1 = 0) {
				GuiControl, ,SliderOne, % SliderOne := 50
			}
		} else If (ThisSlider = "SliderTwo"){
			if (ChkBxPot2 = 1) {
				IniWrite, % %ThisSlider%, %ConfigFile%, ScriptGuiVars, % ThisSlider
				IniWrite, % xBtmRec2 := (wRec2/100)*SliderTwo, %ConfigFile%, ScriptGuiVars, xBtmRec2
				
			} else if (ChkBxPot2 = 0) {
				GuiControl, ,SliderTwo, % SliderTwo := 50
		}}
		GUI, submit, nohide
		return

		ChkBx3:  ; CheckBox for Timer1
		ChkBx4:  ; CheckBox for Timer2
		ChkBx5:  ; CheckBox for Timer3
		ChkBx6:  ; CheckBox for Timer4
		GUI, submit, nohide
		Loop, 4 {
			ChkBx := "ChkBx"A_Index + 2

			if (TmrSndKey%A_Index% = "SendKey" && %ChkBx% = 1) {
				GuiControl, , %ChkBx%, 0
				return
			}
			
			if (ChkBx = A_ThisLabel) {
				Hotkey, ~!%A_index%, Alt%A_Index%, on
				if ((%ChkBx% = 1) && (TmrSndKey%A_Index% = "" || Tmr%A_Index% = "")) {
					GuiControl, ,%ChkBx%, 0
					GUI, submit, nohide
				} else if (%ChkBx% = 0 && Tmr%A_Index% != "") {
					Tmr%A_Index% := TmrSndKey%A_Index% := TmrMnt%A_Index% := TmrSec%A_Index% := ""
					Hotkey, ~!%A_index%, Alt%A_Index%, off
					GuiControl, text, TmrSndKey%A_Index%
					GuiControl, text, Tmr%A_Index%
				}
				
				InfoTmrSndKey%A_Index% := TmrSndKey%A_Index%
				GuiControl, , StrTmr%A_Index%, % "Timer"A_Index ".`t    Key to send:`t" TmrSndKey%A_Index% "`n`t    Timer Period:`t" Tmr%A_Index%
				IniWrite, % %ChkBx%, %ConfigFile%, ScriptGuiVars, %ChkBx%
				IniWrite, % Tmr%A_Index%, %ConfigFile%, ScriptGuiVars, % "Tmr"A_Index
				IniWrite, % TmrSndKey%A_Index%, %ConfigFile%, ScriptGuiVars, % "TmrSndKey"A_Index
		}}

		GuiControl, , TmrSndKey, % "`nSendkey on interval:`nKey to send:`t " InfoTmrSndKey1 "`nKey to send:`t " InfoTmrSndKey2 "`nKey to send:`t " InfoTmrSndKey3 "`n""Key to send:`t " InfoTmrSndKey4
		GuiControl, , TmrTime,`nInterval: `t%Tmr1%`nInterval: `t%Tmr2%`nInterval: `t%Tmr3%`nInterval: `t%Tmr4%
		ToggleControls(A_ThisLabel)
		return

		; SpamKey.
		ChkBx7:
		GUI, submit, nohide
		if (ChkBx7 = 1) {
			if (!HotkeySpam || HotkeySpam = "Hotkey" || !SpamSndKey) {
				GuiControl, ,ChkBx7, 0
				return
			}
			
			if (HotkeySpam && SpamSndKey)
				Hotkey, ~%HotkeySpam%, SpamKey, On
			
			if (!SpamSndKey)
				GuiControl, ,SpamSndKey, % SpamSndKey := HotkeySpam
			
			InfoHkSpam := HotkeySpam, InfoSpamKeySnd := SpamSndKey, InfoSndFrq := 1000 // SpmKeySndFrq

		} else if (ChkBx7 = 0) {
			if (HotkeySpam && SpamSndKey)
				Hotkey, ~%HotkeySpam%, SpamKey, off

			SpamKey := ChkBx7 := SpamSndKey := HotkeySpam := InfoHkSpam := InfoSpamKeySnd := InfoSndFrq := DDLselect1 := "", SpmKeySndFrq := 100
			IniWrite, %A_Space%, %ConfigFile%, ScriptGuiVars, SpmKeySndFrq
		}
		For i, v in ["HotkeySpam", "SpamSndKey", "ChkBx7", "DDLselect1"]
			IniWrite, % %v%, %ConfigFile%, ScriptGuiVars, %v%
		i:=0,v:=""
		ToggleControls("ChkBx7")
		gosub, UpdKeyInfo
		return

		; SequenceKeys.
		ChkBx8:
		GUI, submit, nohide
		if (A_GuiControl = "SeqReset" && (ChkBx8 = 0 || ChkBx8 = "")) {
			AddText(1)
			return
		}

		if (ChkBx8 = 1) {
			if (!HotkeySeq1 || HotkeySeq1 = "Hotkey" || !SndkeySeq1 || !SndkeySeq2 || SndkeySeq1 = "SendKey" || SndkeySeq2 = "SendKey"){
				GuiControl, ,ChkBx8, 0
				return
			}
			
			Loop 3 {
				SeqKey := "SendKey" A_Index+2
				if (%SeqKey% = "SendKey")
					GuiControl, , % SeqKey
			}
			
			if (HotkeySeq1 && HotkeySeq2 = "Hotkey"){
				GuiControl, ,HotkeySeq2, % HotkeySeq2 := ""
				InfoSeqKeys1:=HotkeySeq1, InfoSeqKeys2:=""
				Hotkey, ~%HotkeySeq1%, SequenceKeys, On
			} else if ((HotkeySeq1 && HotkeySeq2) && (HotkeySeq2 != "Hotkey")) {
				Hotkey, ~%HotkeySeq1%, SequenceKeys, On
				Hotkey, ~%HotkeySeq2%, SequenceKeys, On
				InfoSeqKeys1:=HotkeySeq1,InfoSeqKeys2:=HotkeySeq2
			}
			
			if (SeqKeysModKey && HotkeySeq1 && HotkeySeq2) {
				Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, On
				Hotkey, ~%SeqKeysModKey% & %HotkeySeq2%, SequenceKeys, On
			} else if (SeqKeysModKey && HotkeySeq1) {
				Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, On
			}
			
			loop, 5
			{
				if (SndkeySeq%A_index% = "SendKey") {
					SndkeySeq%A_index% := ""
					GuiControl, ,SndkeySeq%A_index%, 
			}}
			InfoSndkeySeq1:=SndkeySeq1,InfoSndkeySeq2:=SndkeySeq2
			InfoSndkeySeq3:=SndkeySeq3,InfoSndkeySeq4:=SndkeySeq4,InfoSndkeySeq5:=SndkeySeq5,InfoSeqKeysModKey:=SeqKeysModKey
		} 
		Else if (ChkBx8 = 0) {
			;GuiControl, Choose, DDL2, 1
			if (HotkeySeq1 && !HotkeySeq2) {
				Hotkey, ~%HotkeySeq1%, SequenceKeys, off
			} else if ((HotkeySeq1 && HotkeySeq2) && (HotkeySeq2 = "Hotkey")) {
				Hotkey, ~%HotkeySeq1%, SequenceKeys, off
			} else if (HotkeySeq1 && HotkeySeq2) {
				Hotkey, ~%HotkeySeq1%, SequenceKeys, off
				Hotkey, ~%HotkeySeq2%, SequenceKeys, off
			}
			
			if (SeqKeysModKey && HotkeySeq1 && HotkeySeq2) {
				if (HotkeySeq2 = "Hotkey") {
					Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, off
				} else {
					Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, off
					Hotkey, ~%SeqKeysModKey% & %HotkeySeq2%, SequenceKeys, off
				}
			} else if (SeqKeysModKey && HotkeySeq1) {
				Hotkey, ~%SeqKeysModKey% & %HotkeySeq1%, SequenceKeys, off
			}
			
			SeqKeysModKey:=ChkBx8:=HotkeySeq1:=HotkeySeq2:=SndkeySeq1:=SndkeySeq2:=SndkeySeq3:=SndkeySeq4:=SndkeySeq5:=InfoSeqKeys1:=InfoSeqKeys2:=InfoSndkeySeq1:=InfoSndkeySeq2:=InfoSndkeySeq3:=InfoSndkeySeq4:=InfoSndkeySeq5:=InfoSeqKeysModKey:=DDL2:=Key1:=Key2:=Key3:=Key4:=Key5:=CurrentPos:=TotalInUse:=""
		}
		; Save changes
		For i, v in ["ChkBx8", "SeqKeysModKey", "DDL2", "HotkeySeq1", "HotkeySeq2", "SndkeySeq1", "SndkeySeq2", "SndkeySeq3", "SndkeySeq4", "SndkeySeq5"] 
			IniWrite, % %v%, %ConfigFile%, ScriptGuiVars, %v%
		i:=0,v:=""

		; ReSubmit old value's to Gui so individual key's can be changed.
		Gui, Submit, NoHide
		ToggleControls("ChkBx8")
		gosub, UpdKeyInfo
		return

		; Get the selected item from any of the DropDown lists.
		DDLGetSelected:
		GUI, Submit, NoHide
		if (A_GuiControl = "DDL1") {
			ControlGet, SelectFromList, Choice, , , ahk_id %hWndProfile%
			SelectFromList := RTrim(SelectFromList, OmitChars)
			PostMessage, Cb_ShowDropDown, 0,,, ahk_id %hWndProfile%
			GuiControl, hide, PrfDel
			;SendMessage, Cb_GetCurSel , , , , ahk_id %hWndProfile%
			
			IniRead, ExeFile, % ClientProfiles SelectFromList "\Settings.ini", ScriptGuiVars, ExeFile
			IniRead, ClientApp, % ClientProfiles SelectFromList "\Settings.ini", ScriptGuiVars, ClientApp
			IniRead, bAdmin, % ClientProfiles SelectFromList "\Settings.ini", ScriptGuiVars, bAdmin, 0
			
			; Checks if the path to the ClientApp.exe still is valid.
			If (!FileExist(ClientApp)) {
				If (MessageBox("Error: " ExeFile " missing", "The application .exe is missing for profile: " SelectFromList
				. 							"`nMissing:`n" A_space ClientApp  "`n`n" 
				.							"It is probaly uninstalled from you're sysytem.`n"
				.							 "Do you want to keep the profile?") = "No") { 
					FileRemoveDir, % ClientProfiles SelectFromList, 1
				}
				gosub, ReloadScript
				Exit
			}
			
			If (bAdmin = 1) {
				if (MessageBox("Elevated:","The system rights for this profile are elevated.`n "
				.						 "You will need te restart the script manualy for changes to apply.`n`n " 
				.						 "Do you want to load this profile ?") = "No") {
					return
			}}
		/*	
			If ((!InStr(WinTitle, "Drop game.exe here")) && (!InStr(WinTitle, "Ready to start: "))) {
				; Create a folder for the current active profile if it does'nt exist.
				if (!FileExist(ClientProfiles WinTitle)) {
					ControlGetText, CtrlTxt, static3, TheGameScript
					FileCreateDir, % ClientProfiles WinTitle
					
					; Copy setting files from old active profile, back to there save location.
					For i, v in [ConfigFile, UserCode, KeyMap]
						FileCopy, % v, % ClientProfiles WinTitle, 1
					
					; Write changed profile order back to each config file.
					Loop, Settings\ClientProfiles\*.*, 2
						IniWrite, % A_Index, % ClientProfiles A_LoopFileName "\Settings.ini", ScriptGuiVars, CurrentPosNr
			}}
		*/	

			; Copy setting files from current active profile, back to there save location.
			FileDelete, % ClientProfiles WinTitle "\*.*"
			For i, v in [ConfigFile, UserCode, KeyMap]
				if (FileExist(v))
					FileCopy, % v, % ClientProfiles WinTitle, 1

			; Refresh list order
			Loop, Settings\ClientProfiles\*.*, 2
				IniWrite, % A_Index, % ClientProfiles A_LoopFileName "\Settings.ini", ScriptGuiVars, CurrentPosNr
			
			
			FileDelete, % ActiveProfile "\*.*"
			; Copy setting files for selected profile to the active profilefolder.
			For i, v in ["Settings.ini", "UserCode.ahk", "KeyMap.ahk"]
				FileCopy, % ClientProfiles SelectFromList "\" v, %ActiveProfile%, 1
			i:=0,v:=""	
			
			If (bAdmin = 1) 
				ExitApp
			Else
				gosub, ReloadScript

		} Else if (A_GuiControl = "DDL2") {
			if (DDL2 = 1)
				IniWrite, %a_space%, %ConfigFile%, ScriptGuiVars, DDL2
			ControlGet, SelectFromList, Choice, , , ahk_id %hWndModKey%
			If(SelectFromList = "Modifier Key's"){
				SeqKeysModKey := ""
				return
			}
			SeqKeysModKey := SelectFromList
		}
		return
	}
	{	; ------------------------------------ Labels and hotkeys for send key on interval -----------------------------------

		; Formatting input for timer periods to mm:ss, m:s or ss
		TimerFormat:
		SetBatchLines -1
		GUI, submit, nohide
		Loop, 4 {
			ChkBx := "ChkBx"A_Index + 2
			if (%ChkBx% = 0) {
				; True when whatever SubStr returns is greater than 60
				if (SubStr(Tmr%A_Index%, InStr(Tmr%A_Index%, ":") +1) > 60) {
					
					; Auto insert a colon on the thirth position when the following conditions are met.
					; 'TmrNr' holds 3 charackters, the first two characters are 60 or smaler and no colon already exist in 'TmrNr'. 
					if (StrLen(Tmr%A_Index%) = 3 && SubStr(Tmr%A_Index%, 1, 2) <= 60 && !InStr(Tmr%A_Index%, ":")) {
						GuiControl, Text, Tmr%A_Index%, % StrReplace(Tmr%A_Index%, SubStr(Tmr%A_Index%, 1, 3), SubStr(Tmr%A_Index%, 1, 2) ":" SubStr(Tmr%A_Index%, 3, 1))
						
					; When value for seconds is greater then 60, it will be removed. Timer format is m:ss
					} else if (InStr(Tmr%A_Index%, ":") = 2) {
						GuiControl, Text, Tmr%A_Index%, % SubStr(Tmr%A_Index%, 1, 2)
					
					; When value for seconds is greater then 60, it will be removed. Timer format is mm:ss
					} else if (InStr(Tmr%A_Index%, ":") = 3) {
						GuiControl, Text, Tmr%A_Index%, % SubStr(Tmr%A_Index%, 1, 3)
					
					; When the value for seconds are greater then 60, it will be removed. Timer format is ss
					} else if (StrLen(Tmr%A_Index%) <= 2) {
						GuiControl, Text, Tmr%A_Index%
					}
					
					ControlSend, %ClsNNCurrent%, {end}
					break
				}
				
				; Press TAB will insert a colon at position two or three
				if ((InStr(Tmr%A_Index%, A_tab) = 2 && StrLen(Tmr%A_Index%) = 2) || (InStr(Tmr%A_Index%, A_tab) = 3 && StrLen(Tmr%A_Index%) = 3)) {
					GuiControl, Text, Tmr%A_Index%, % RTrim(Tmr%A_Index%) ":"
					ControlSend, %ClsNNCurrent%, {end}
					GUI, submit, nohide
				}
				
				; Allow only one collon to exist. OR remove empty tab/space when a colon exist and tab is pressed again.
				if (InStr(Tmr%A_Index%, ":", , , 2) || InStr(Tmr%A_Index%, ":", , , 1) && InStr(Tmr%A_Index%, A_tab)) {
					ControlSend, %ClsNNCurrent%, {bs}
				}
				GUI, submit, nohide
		}}
		return
	}
	{	; ------------------------------ All hotkey's below here will effect client window only ------------------------------

		#IfWinActive, ahk_group ClientGroup
		#Include *i Settings\ActiveProfile\UserCode.ahk
		#Include *i Settings\ActiveProfile\KeyMap.ahk

		; Disable window startmenu when client window is active.
		StartMenuOff:
		return

		; While client window is active, hotkey's alt+1 - 4 will toggle each timer.
		; Timer hotkey's only exist when the timer checkbox is enabled.
		Alt1:
		Alt2:
		Alt3:
		Alt4:
		Loop 4 {
			if (StrReplace(A_ThisHotkey, "~!") = A_index) {
				TmrTgglState%A_index% := TmrTgglState%A_index%<On ? On : Off
				if (TmrTgglState%A_index% = 1) {
					TotalOn += 1, Timer := "Timer", Timer .= TotalOn, Timer%TotalOn% := "Tmr"A_index
					SoundPlay, C:\Windows\Media\chimes.wav
				
					if (TotalOn = 1)
						RunningOn := 1
					
				} else if (TmrTgglState%A_index% = 0) {
					TmrMnt%A_index% := TmrSec%A_index% := col%A_Index% := Timer%A_Index% := "", WaitNext := TotalOn -= 1

					If (TotalOn != 0)
						SoundPlay, C:\Windows\Media\ding.wav
		}}}
		KeyWait, LAlt
		if(TotalOn > 0 && RunningOn = 1) {
			SetTimer, SendKeyOnInterval, 10
			
		} else if(TotalOn = 0) {
			AltS: 	; Stop all running counters using hotkey alt+s.
			SoundPlay, C:\Windows\Media\ding.wav
			SetTimer, SendKeyOnInterval, Off
			
			loop 4 {
				if (Tmr%A_Index% = "00:00")
					Tmr%A_Index% := ""
				
				Timer%A_index%:=TmrTgglState%A_index%:=TmrMnt%A_index%:=TmrSec%A_index%:=Col%A_index%:=A_NextSecond:=""
			}
			
			RunningOn:=WaitNext:=TotalOn:=0
			GuiControl, , TmrTime,`nInterval: `t%A_space%%Tmr1%`nInterval: `t%A_space%%Tmr2%`nInterval: `t%A_space%%Tmr3%`nInterval: `t%A_space%%Tmr4%
			return
		}
		return

		; Lable for settimer
		SendKeyOnInterval:
		; Pause timers when eighter Alt is down, so timers can be toggled on/off.
		; Or when client window does not exist as top lvl window.
		if (GetKeyState("LAlt", "P") || hWndClient != WinExist("A"))
			return
		; Reset variables 'i' and 'A_NextSecond' once a second.
		; On the first couple of calls, variables will be created for each enabled timer.
		; Cousing each timer to start one second after the other.
		if (A_TickCount >= A_NextSecond) {
			A_NextSecond := A_TickCount+1000, i := 0
			
			; When the total numer of enabled timers is greater then variable 'WaitNext',
			; timer periods will be created below.
			if (WaitNext < TotalOn) {
				WaitNext += 1, Tmr := SubStr(Timer%WaitNext%, 4, 1)

				; Creating variable for seconds when variable 'TmrNr' is not empty and only holds 2 digits. Meaning only seconds are configured by the user.
				; Also add 1 to the value for seconds. Otherwise the timer would be off by one second, because it is substracted within the next 10mls.
				if (Strlen(Tmr%Tmr%) <= 2 && !InStr(Tmr%Tmr%, ":") && Tmr%Tmr% != "") {
					TmrMnt%Tmr% := "", TmrSec%Tmr% := Tmr%Tmr% + 1

				; Create variables for Minutes : Seconds. TmrMnt%Tmr% : TmrSec%Tmr%
				} else if (Strlen(Tmr%Tmr%) >= 3 && InStr(Tmr%Tmr%, ":")) {
					TmrMnt%Tmr% := SubStr(Tmr%Tmr%, 1, InStr(Tmr%Tmr%, ":") -1), TmrSec%Tmr% := SubStr(Tmr%Tmr%, InStr(Tmr%Tmr%, ":")+1), col%Tmr% := ":"
				
					; Below lines will basicaly add one to seconds.
					if (TmrSec%Tmr% = 0 || TmrSec%Tmr% = 00)
						TmrSec%Tmr% := 60, TmrMnt%Tmr% -= 1
					else
						TmrSec%Tmr% += 1
		}}}

		; Checks 4 times within each second where to substrack 1 from minutes or seconds as long var 'i' is smaler then 4, and is not empty.
		; The value in variable 'i' is used to indicate which timer is currenty in the "loop" of settimer.
		if (i < 4 && i != "") {
			i += 1
			; Minutes are optional, so not using it here as condition to see whatever something needs a decrement.
			; Conditions are based on seconds beeing larger then or equal to zero and the hotkey is enabled for the current timer.
			if (TmrSec%i% >= 0 && TmrTgglState%i% = 1) {

				; When minutes are not configured, decrement seconds by 1 and skip all other statements below.
				if (TmrMnt%i% = "" ) {
					TmrSec%i% -= 1

				; When both minutes : seconds are in use. Start counting down the first cycle of seconds when seconds are larger then or equal to 0.
				} else if (TmrMnt%i% > 0 && TmrSec%i% >= 0) {
					TmrSec%i% -= 1

					; Substrack 1 from Minutes. Reset seconds for next countdown cycle.
					; While minutes is greater then zero, AND once seconds is equal or smaller then zero.
					if (TmrMnt%i% > 0 && TmrSec%i% <= 0)
						TmrMnt%i% -= 1, TmrSec%i% := 60

				; Almost the same as the first "else if", but here the value for seconds SET BY THE USER are already used.
				} else if (TmrMnt%i% > 0 && TmrSec%i% > 0) {
					TmrSec%i% -= 1

					; A minute past by, but there are some more to countdown. So minutes -1 and reset seconds.
					if (TmrMnt%i% > 0 && TmrSec%i% = 1)
						TmrMnt%i% -= 1, TmrSec%i% := 60

				; Countdown the last 60 seconds when all minutes are used up.
				} else if (TmrMnt%i% = 0 && TmrSec%i% > 0) {
					TmrSec%i% -= 1
			}}
			; Create variable for the current timer to send it's asociated key and reset the periods back to user input.
			; Format = Seconds 
			if (TmrMnt%i% = "" && TmrSec%i% = 0 && TmrTgglState%i% = 1) {
				TmrSndKey := TmrSndKey%i%, TmrSec%i% := Tmr%i%
				SendEvent, {%TmrSndKey% down}{%TmrSndKey% up}

			; Format = Minute : Seconds
			} else if (TmrMnt%i% = 0 && TmrSec%i% = 0 && TmrTgglState%i% = 1) {
				TmrMnt%i% := SubStr(Tmr%i%, 1, InStr(Tmr%i% , ":")-1), TmrSec%i% := SubStr(Tmr%i%, InStr(Tmr%i% , ":")+1), TmrSndKey := TmrSndKey%i%
				SendEvent, {%TmrSndKey% down}{%TmrSndKey% up}
				GuiControl, text, TmrTime, Interval: `t%TmrMnt1%%col1%%TmrSec1%`nInterval: `t%TmrMnt2%%col2%%TmrSec2%`nInterval: `t%TmrMnt3%%col3%%TmrSec3%`nInterval: `t%TmrMnt4%%col4%%TmrSec4%
			}
			; Once a second, GuiControl updates all controls in the Gui.
			if (i = 4)
				GuiControl, text, TmrTime,`nInterval: `t%TmrMnt1%%col1%%TmrSec1%`nInterval: `t%TmrMnt2%%col2%%TmrSec2%`nInterval: `t%TmrMnt3%%col3%%TmrSec3%`nInterval: `t%TmrMnt4%%col4%%TmrSec4%
		}
		return

		AutoWalk:
		AutoWalk(HotkeyWalk)
		return

		ToggleAutoPot:
		if (ChkBxPot1 && A_ThisHotkey = HotkeyPot1) {
			PxlSearch1 := PxlSearch1 != 1 ? 1 : 0
			
			if (PxlSearch1 = 1)
				SetTimer, PxlSrch1, 1000
			else
				SetTimer, PxlSrch1, off
			
		}
		if (ChkBxPot2 && A_ThisHotkey = HotkeyPot2) {
			PxlSearch2 := PxlSearch2 != 1 ? 1 : 0
			
			if (PxlSearch2 = 1)
				SetTimer, PxlSrch2, 1000
			else
				SetTimer, PxlSrch2, off
		}
		return

		PxlSrch1:
		; PixelGetColor, OutputVar, X, Y [, Alt|Slow|RGB]
		; The default left-to-right search order can be inverted by swapping X1 and X2 in the parameter list. 
		; In other words, if X1 is greater than X2, the search will be conducted from right to left, starting at column X1.
		; Similarly, if Y1 is greater than Y2, each column of pixels to be searched starting at the bottom rather than the top. 
		;PixelSearch, , , %xTopRec1%, %yTopRec1%, %xBtmRec1%, %yBtmRec1%, %SearchClr1%, 2, Fast RGB	; Search order L to R  - T to B
		;PixelSearch, , , %yBtmRec1%, %xTopRec1%, %xBtmRec1%, %yTopRec1%, %SearchClr1%, 2, Fast RGB	; Search order L to R - B to T
		;PixelSearch, , , %xBtmRec1%, %yTopRec1%, %xTopRec1%, %yBtmRec1%, %SearchClr1%, 2, Fast RGB	; Search order R to L - T to B
		;PixelSearch, , , %xBtmRec1%, %yBtmRec1%, %xTopRec1%, %yTopRec1%, %SearchClr1%, 2, Fast RGB ; Search order R to L - T to B
		PixelSearch, , , %xTopRec1%, %yTopRec1%, %xBtmRec1%, %yBtmRec1%, %SearchClr1%, 2, Fast RGB
		If (ErrorLevel = 1)
			;SendEvent
		return

		PxlSrch2:
		PixelSearch,pX2, pY2,%xTopRec2%, %yTopRec2%, %xBtmRec2%, %yBtmRec2%, %SearchClr2%, 2, Fast RGB
		return

		SpamKey:
		SetBatchLines -1
		DllCall("QueryPerformanceFrequency", "Int64*", lpFrequency), lpFrequency //= 1000
		Hotkey, ~%HotkeySpam%, SpamKey, off
		while Getkeystate(HotkeySpam, "P") {
			DllCall("QueryPerformanceCounter", "Int64*", lpCounter)
			if (lpCounter // lpFrequency >= NextCycle) {
				NextCycle := (lpCounter // lpFrequency) + SpmKeySndFrq
				Send, {%SpamSndKey% down}{%SpamSndKey% up}
		}}
		Hotkey, ~%HotkeySpam%, SpamKey, On
		return

		SequenceKeys:
		if (SeqKeysModKey && ChkBx8 = 1) {
			if getkeystate(SeqKeysModKey, "P")
				KeySequence(SndkeySeq1, SndkeySeq2, SndkeySeq3, SndkeySeq4, SndkeySeq5)
		} else if (!SeqKeysModKey && ChkBx8 = 1) {
			KeySequence(SndkeySeq1, SndkeySeq2, SndkeySeq3, SndkeySeq4, SndkeySeq5)
		}
		return
	}
}
Last edited by megnatar on 24 Feb 2018, 05:28, edited 1 time in total.
Xatmo

Re: The Game Script Beta 1

24 Feb 2018, 02:57

very nice i like the layout of the gui

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 36 guests