Login

russian armor

AutoHotkey script for casting

19 Dec 2022, 20:33 PM
#1
avatar of Mithiriath
Director of Social Media Badge

Posts: 830 | Subs: 3

Hello,

I share here my AutoHotkey script for casting. Maybe someone might be interested.

What does the script do?


This script has 3 purposes:
  • Regroup all hotkeys (around WASD as arrow) in the same area of the keyboard like the gridkey format in-game ;
  • Manage players/teams score during tournament without having to switch to OBS windows to update score;
  • Automatically change OBS scene when we toggle in-game the tactical map.

As you know, we have on most keyboards keys from F1 to F12 but do you know keys F13 to F24 exist too?

Why use these keys you can tell me. Well, the great advantage of keys F13 to F24 is that no app or Windows use it. So we can use these keys in every situation no matter which app is focus, there is no risk of activating a shortcut that we don't know about. It also avoids having to use hotkeys with multiple keys like Ctrl + Alt + Key.

So to begin, every keys from F6 to F12 are remap on F13 to F19. It means when we press F6 key, it sends F13 as if we had a F13 key on our keyboard. I didn't remap keys from F1 to F5 because we can use it in CoH.

1) Regroup all hotkeys





Buttons used in that script:
  • CapsLock = Play/Pause replay
  • q = Toggle fog of war
  • w = Arrow Up
  • e = Toggle UI
  • r = Camera follow selection
  • t = Players statistics
  • a = Left
  • s = Down
  • d = Right
  • f = Follow player camera
  • z = Slow down replay
  • x = Speed up replay
  • c = Toggle tactical map
  • v = Fast double press to reset Left Score to 0. "Slow" press to increment Left Score by 1.
  • b = Fast double press to reset Right Score to 0. "Slow" press to increment Right Score by 1.
  • F15 = My hotkey to show on OBS "normal ingame" scene;
  • F16 = My hotkey to show on OBS "tactical map ingame" scene.

2) Manage players/teams score


  • v = Fast double press to reset Left Score to 0. "Slow" press to increment Left Score by 1.
  • b = Fast double press to reset Right Score to 0. "Slow" press to increment Right Score by 1.

Basically AutoHotkey read score then write score in 2 text files configured in OBS (see section OBS configuration below).

3) Automatically change OBS scene


  • c = Toggle tactical map

I have 3 cases:
  • I click on c:
    • If the tactical map is closed then it open it and switch on OBS to "tactical map in-game" scene.
    • If the tactical map is opened then it close it and switch on OBS to "normal in-game" scene.

  • Tactical map is opened and I double click on it: It will close the tactical map and switch on OBS to "normal in-game" scene.

OBS configuration - Part 1


  • Open OBS;
  • Create 2 files on your computer named: score_left.txt and score_right.txt
  • Select your in-game scene -> Add Source:
    • First Text (GDI+): Name it Score Left -> Check Read from file box -> Browse -> Select score_left.txt -> OK;
    • Second Text (GDI+): Name it Score Right -> Check Read from file box -> Browse -> Select score_right.txt -> OK.


The script below is only compatible with the version 2 of AutoHotkey.
Code
; AutoHotkey script for CoH 2 casting - Version: 3
#Warn ; Enable warnings to assist with detecting common errors.
SendMode "Input" ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir A_InitialWorkingDir ; Ensures a consistent starting directory.
SetKeyDelay 50, 50
SetMouseDelay 50

#SuspendExempt
F6::F13
F7::F14
F8::F15
F9::F16
F10::F17
F11::F18
F12::F19
F19::Suspend ; Toggle Suspend/Re-enable this autohotkey script
#SuspendExempt False

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Company of Heroes 2 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

global InTacticalMap := 0
TacticalMapHK := "{Numpad0}"

; Variables you need to configure:
ObsSceneIg := "{F15}" ; F15 = My hotkey to show on OBS "normal ingame" scene
ObsSceneIgTM := "{F16}" ; F16 = My hotkey to show on OBS "tactical map ingame" scene
FileScoreLeft := "" ; Example: "C:\obs\score_left.txt"
FileScoreRight := "" ; Example: "C:\obs\score_right.txt"

if (FileScoreLeft = ""){
MsgBox "'FileScoreLeft' variable (line 34) is empty. Configure a filename (absolute file path)."
return
}
if not FileExist(FileScoreLeft){
MsgBox "The file '" FileScoreLeft "' in 'FileScoreLeft' variable does not exist."
return
}
if (FileScoreRight = ""){
MsgBox "'FileScoreRight' variable (line 35) is empty. Configure a filename (absolute file path)."
return
}
if not FileExist(FileScoreRight){
MsgBox "The file '" FileScoreRight "' in 'FileScoreRight' variable does not exist."
return
}

#HotIf WinActive("ahk_exe RelicCoH2.exe") ; Hotkeys enable only when CoH2 windows is focus/in the foreground
*CapsLock::SendInput "{SC045}" ; Play/Pause replay
q::>^F ; Toggle fog of war
w::Up
e::>^U ; Toggle UI
r::' ; Camera follow selection
t::>^` ; Players statistics
a::Left
s::Down
d::Right
f:: ; Follow camera
{
MouseGetPos &xpos, &ypos
Click 895, 1185 ; Click on the "Follow camera" button for 1920 x 1200 resolution
;Click 895, 1065 ; Click on the "Follow camera" button for 1920 x 1080 (1080p) resolution
Click xpos, ypos
}
z::- ; Slow down replay
x::= ; Speed up replay
c:: ; Toggle tactical map and switch between "normal ingame" OBS scene and "tactical map ingame" OBS scene
{
global InTacticalMap
ControlSend TacticalMapHK,,"ahk_exe RelicCoH2.exe"
if (InTacticalMap=1) ; Close tactical map and switch to "normal ingame" OBS scene
{
WinActivate "OBS"
SendInput ObsSceneIg
InTacticalMap := 0
WinActivate "Company Of Heroes 2"
}
else ; Open tactical map and switch to "tactical map ingame" OBS scene
{
WinActivate "OBS"
SendInput ObsSceneIgTM
InTacticalMap := 1
WinActivate "Company Of Heroes 2"
}
}
v:: ; Fast double press to reset Left Score to 0. "Slow" press to increment Left Score by 1.
{
if (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey<200)
{
FileDelete FileScoreLeft
try
FileObj := FileOpen(FileScoreLeft, "w")
catch as Err
{
MsgBox "Can't open '" FileScoreLeft "' for writting.`n`n" Type(Err) ": " Err.Message
return
}
Score := 0
FileObj.Write(Score)
return
}
try
FileObj := FileOpen(FileScoreLeft, "r")
catch as Err
{
MsgBox "Can't open '" FileScoreLeft "' for reading.`n`n" Type(Err) ": " Err.Message
return
}
Score := FileObj.Read(1)
if not (IsInteger(Score)){
Score :=0
}
FileObj.Close()
Score := Score + 1
FileDelete FileScoreLeft
try
FileObj := FileOpen(FileScoreLeft, "w")
catch as Err
{
MsgBox "Can't open '" FileScoreLeft "' for writting.`n`n" Type(Err) ": " Err.Message
return
}
FileObj.Write(Score)
FileObj.Close()
}
b:: ; Fast double press to reset Right Score to 0. "Slow" press to increment Right Score by 1.
{
if (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey<200)
{
FileDelete FileScoreRight
try
FileObj := FileOpen(FileScoreRight, "w")
catch as Err
{
MsgBox "Can't open '" FileScoreRight "' for writting.`n`n" Type(Err) ": " Err.Message
return
}
Score := 0
FileObj.Write(Score)
return
}
try
FileObj := FileOpen(FileScoreRight, "r")
catch as Err
{
MsgBox "Can't open '" FileScoreRight "' for reading.`n`n" Type(Err) ": " Err.Message
return
}
Score := FileObj.Read(1)
if not (IsInteger(Score)){
Score :=0
}
FileObj.Close()
Score := Score + 1
FileDelete FileScoreRight
try
FileObj := FileOpen(FileScoreRight, "w")
catch as Err
{
MsgBox "Can't open '" FileScoreRight "' for writting.`n`n" Type(Err) ": " Err.Message
return
}
FileObj.Write(Score)
FileObj.Close()
}
~*LButton:: ; Case where tactical map closed with double click and switch to "normal ingame" OBS scene
{
global InTacticalMap
if (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey<400 and InTacticalMap=1)
{
WinActivate "OBS"
SendInput ObsSceneIg
InTacticalMap := 0
WinActivate "Company Of Heroes 2"
}
}
#HotIf


AutoHotkey script configuration


  • Download Notepad++: Go on the official site: https://notepad-plus-plus.org/downloads -> Click on the last version -> Download 64-bit x64 -> Installer;
  • Download AutoHotkey and install it: Go on the official site: https://www.autohotkey.com/download -> Click on Download AutoHotkey v2.*. The script above is only compatible with the version 2 of AutoHotkey;
  • Click on New Script

  • Enter the name of your script -> Click on Minimal for v2 -> Create

  • Open the AutoHotkey script with Notepad++

  • Copy the code above in the script;
  • Configure in the AutoHotkey script the following variables (I can help you with that part):
    • ObsSceneIg := "{F15}"
      • Default value is F15 but you can change it;

    • ObsSceneIgTM := "{F16}"
      • Default value is F16 but you can change it;

  • FileScoreLeft := ""
    • Add the filename (absolute file path) of "score_left.txt".Like: FileScoreLeft := "C:\obs\score_left.txt"

  • FileScoreRight := ""
    • Add the filename (absolute file path) of "score_right.txt".Like: FileScoreRight := "C:\obs\score_right.txt"

  • Then double click on scriptname.ahk to execute it;
  • You can Copy the file and Paste shortcut in the folder C:\Users\YourUsername\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup if you want Windows to execute it automatically on startup.

OBS configuration - Part 2


  • Open OBS;
  • You must have at least 2 scenes. Your "normal in-game" scene and "tactical map in-game". If not create the scenes with + button;

  • Menu: File -> Settings;

  • Hotkeys;
    • Go to your "normal in-game" scene (In-game for me) -> Switch to scene line -> Configure the same hotkey (F15 for me) as the one configured in the AutoHotkey script (aka ObsSceneIg := "{F15}" by default);
    • Go to your "tactical mapin-game" scene (In-game Tactical Map for me) -> Switch to scene line -> Configure the same hotkey (F16 for me) as the one configured in the AutoHotkey script (aka ObsSceneIgTM := "{F16}" by default).

20 Dec 2022, 15:21 PM
#2
avatar of Mithiriath
Director of Social Media Badge

Posts: 830 | Subs: 3

I updated the first post.

The AutoHotkey script can now manage players/teams score during tournament without having to switch to OBS windows to update score.
1 user is browsing this thread: 1 guest

Ladders Top 10

  • #
    Steam Alias
    W
    L
    %
    Streak
Data provided by Relic Relic Entertainment

Replay highlight

VS
  • U.S. Forces flag cblanco ★
  • The British Forces flag 보드카 중대
  • Oberkommando West flag VonManteuffel
  • Ostheer flag Heartless Jäger
uploaded by XXxxHeartlessxxXX

Board Info

402 users are online: 402 guests
0 post in the last 24h
2 posts in the last week
28 posts in the last month
Registered members: 49388
Welcome our newest member, KETTA
Most online: 2043 users on 29 Oct 2023, 01:04 AM