;;;HOW TO SETUP;;; First download and install Autohotkey.com (very simple)
;;;;;Then Create New Autohotkey Script and copy this into the new .AHK file
;;;;;OR simply download this file, rename and erase .ahk.TXT to just .AHK
;;;;;Place in your WC3 folder and create shortcut on desktop
;;;;;Usually requires right-click and setting to Run as Admin
;;;;;German Keyboards can Switch NumPad 8 from Y to Z at the bottom
;;;;;In WC3 press F5 to pause Script on/off for chat
;;;;;Now your Invetory hotkeys are switched to TYGHBN
;;;;;Also disables WinKey or Alt+QQ from closing your game
;;;;;If mouse supports extra buttons can be remapped at bottom


#SingleInstance force		;force a single instance
#HotkeyInterval 0		;disable the warning dialog if a key is held down
#InstallKeybdHook		;Forces the unconditional installation of the keyboard hook
#UseHook On			;might increase responsiveness of hotkeys
#MaxThreads 20			;use 20 (the max) instead of 10 threads
SetBatchLines, -1		;makes the script run at max speed
SetKeyDelay , -1, -1		;faster response (might be better with -1, 0)
;Thread, Interrupt , -1, -1	;not sure what this does, could be bad for timers
SetTitleMatchMode Regex
SetDefaultMouseSpeed, 0 ;Move the mouse faster for mouse moving commands

IfExist, Warcraft III.exe
  menu, tray, Icon, Warcraft III.exe, 1, 1

;;;;; Variables ;;;;;
bInChatRoom := False
bHealthBarOn := False
Return ; End Auto-Execute Section

; AutoCast Function
AutoCast(iSpellQWERHotkey)
{
  MouseGetPos, iMousePosX, IMousePosY
  if (iSpellQWERHotkey == 1)
  {
    iMouseGotoX := A_ScreenWidth*4//5
    iMouseGotoY := A_ScreenHeight*4//5
  }
  else if (iSpellQWERHotkey == 2)
  {
    iMouseGotoX := A_ScreenWidth*4//5
    iMouseGotoY := A_ScreenHeight*22//25
  }
  else if (iSpellQWERHotkey == 3)
  {    iMouseGotoX := A_ScreenWidth*4//5
    iMouseGotoY := A_ScreenHeight*19//20
  }
  else if (iSpellQWERHotkey == 4)
  {
    iMouseGotoX := A_ScreenWidth*17//20
    iMouseGotoY := A_ScreenHeight*4//5
  }
  else if (iSpellQWERHotkey == 5)
  {
    iMouseGotoX := A_ScreenWidth*17//20
    iMouseGotoY := A_ScreenHeight*22//25
  }
  else if (iSpellQWERHotkey == 6)
  {
    iMouseGotoX := A_ScreenWidth*17//20
    iMouseGotoY := A_ScreenHeight*19//20
  }
  else if (iSpellQWERHotkey == 7)
  {
    iMouseGotoX := A_ScreenWidth*9//10
    iMouseGotoY := A_ScreenHeight*4//5
  }
  else if (iSpellQWERHotkey == 8)
  {
    iMouseGotoX := A_ScreenWidth*9//10
    iMouseGotoY := A_ScreenHeight*22//25
  }
  else if (iSpellQWERHotkey == 9)
  {
    iMouseGotoX := A_ScreenWidth*9//10
    iMouseGotoY := A_ScreenHeight*19//20
  }
  else if (iSpellQWERHotkey == 10)
  {
    iMouseGotoX := A_ScreenWidth*19//20
    iMouseGotoY := A_ScreenHeight*4//5
  }
  else if (iSpellQWERHotkey == 11)
  {
    iMouseGotoX := A_ScreenWidth*19//20
    iMouseGotoY := A_ScreenHeight*22//25
  }
  else if (iSpellQWERHotkey == 12)
  {
    iMouseGotoX := A_ScreenWidth*19//20
    iMouseGotoY := A_ScreenHeight*19//20
  }
  Click, Right, %iMouseGotoX%, %iMouseGotoY%
  MouseMove, %iMousePosX%, %iMousePosY%
}

#ifWinActive ahk_class ((WarcraftIII)|(OsWindow)|(Qt5QWindowIcon))

;;;;; Enable/disable all hotkeys ;;;;;
~*Enter::
~*NumpadEnter::
Suspend, Permit
if (bInChatRoom == True)
  return
Suspend
if (A_IsSuspended == true)
{
  SetCapsLockState, Off
}
else
{
  SetCapsLockState, On
  SoundPlay,*48
}
return

;; Escape will cancel chatting, so turn the hotkeys back on
~*Esc::
Suspend, Permit
if (bInChatRoom == True)
  return
Suspend, Off
SetCapsLockState, On
return

*F5::
Suspend, Permit
bInChatRoom := not bInChatRoom
if (bInChatRoom == True)
{
  Suspend, On
  SetCapsLockState, Off
  SoundPlay,*64
}
else
{
  Suspend, Off
  SetCapsLockState, On
  SoundPlay,*48
}
return


; Hotkeys Remapper:

; Disable Windows Key and AltQQ GG
Lwin::return
<!q::return

; Mini-Map Toggles
<!g::<!g
<!r::return
<!t::return
<!a::return
<!f::return
;;to enable formation toggle add ;; to the line above

; Inventory Keys:
t::Send, {Numpad7}
+t::Send, +{Numpad7}
y::Send, {Numpad8}
+y::Send, +{Numpad8}
g::Send, {Numpad4}
+g::Send, +{Numpad4}
h::Send, {Numpad5}
+h::Send, +{Numpad5}
b::Send, {Numpad1}
+b::Send, +{Numpad1}
n::Send, {Numpad2}
+n::Send, +{Numpad2}

; Quick Chat Msgs
Numpad1::SendInput, +{Enter}Careful{Enter}
Numpad2::SendInput, +{Enter}Attack{Enter}
Numpad3::SendInput, +{Enter}Focus Units{Enter}
Numpad4::SendInput, +{Enter}Back{Enter}
Numpad5::SendInput, +{Enter}Rush{Enter}
Numpad6::SendInput, +{Enter}Focus Hero{Enter}
Numpad7::SendInput, +{Enter}TP{Enter}
Numpad8::SendInput, +{Enter}Counter{Enter}
Numpad9::SendInput, +{Enter}Fast Expo{Enter}
Numpad0::SendInput, +{Enter}Repair{Enter}

; User Specified Hotkeys:
Xbutton1::F1
Xbutton2::Numpad7
Mbutton::Tab
; these^ are middle mouse and extra mouse buttons

;;LCtrl::Space
;;Space::LCtrl
;To swap the Ctrl key with the Spacebar just remove the ;; from the 2 lines above