Login

russian armor

Toggle OBS scene when toggle in-game tactical map

19 Dec 2022, 16:21 PM
#1
avatar of Mithiriath
Director of Social Media Badge

Posts: 830 | Subs: 3

Hello,

I share here my AutoHotkey script to automatically change OBS scene when I toggle in-game the tactical map. Maybe someone might be interested.

What does the script do?


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.

Buttons used in that script:
  • XButton2 = Thumb mouse button (the most forward) to open tactical map;
  • F15 = My hotkey to show on OBS "normal ingame" scene;
  • F16 = My hotkey to show on OBS "tactical map ingame" scene.

I have 3 cases:
  • I click on XButton2:
    • 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.

The script below is only compatible with the version 2 of AutoHotkey.
Code
; AutoHotkey script for CoH 2 - Script version: 2
#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

#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

#HotIf WinActive("ahk_exe RelicCoH2.exe") ; Hotkeys enable only when CoH2 windows is focus/in the foreground
XButton2:: ; 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"
}
}
~*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;

  • 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


  • 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).

19 Dec 2022, 18:05 PM
#2
avatar of Vipper

Posts: 13476 | Subs: 1

19 Dec 2022, 22:13 PM
#3
avatar of Mithiriath
Director of Social Media Badge

Posts: 830 | Subs: 3

jump backJump back to quoted post19 Dec 2022, 18:05 PMVipper
well done

Thanks Vipper 🍻
19 Dec 2022, 22:19 PM
#4
avatar of Rosbone

Posts: 2098 | Subs: 2

20 Dec 2022, 15:10 PM
#5
avatar of Mithiriath
Director of Social Media Badge

Posts: 830 | Subs: 3

jump backJump back to quoted post19 Dec 2022, 22:19 PMRosbone
Nice work

Thanks Rosbone 🍻

-------------------

I updated the script to make it easier to modify.
20 Dec 2022, 23:34 PM
#6
avatar of pegasos

Posts: 85

thanks. good sharing.
21 Dec 2022, 11:38 AM
#7
avatar of Mithiriath
Director of Social Media Badge

Posts: 830 | Subs: 3

jump backJump back to quoted post20 Dec 2022, 23:34 PMpegasos
thanks. good sharing.

Thanks pegasos 🍻

I updated my first post to make the script/OBS easier to configure.
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

576 users are online: 1 member and 575 guests
A_E
20 posts in the last 24h
48 posts in the last week
102 posts in the last month
Registered members: 44657
Welcome our newest member, Mitali121
Most online: 2043 users on 29 Oct 2023, 01:04 AM