Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Load Monitor Profile, Adjust Volume, Start Game, Switch Back on Exit

Description
Loads a Monitor Profile, adjusts the volume, starts a game, and changes the Monitor Profile and volume level back on exit. Adjust the code with your preferred monitor profiles and volume levels.
Language
C#.net
Minimum Version
Created By
Frode4
Contributors
-
Date Created
May 5, 2016
Date Last Modified
May 5, 2016

Scripted Function (Macro) Code

using System;
using System.Drawing;

// The 'windowHandle' parameter will contain the window handle for the:
//   - Active window when run by hotkey
//   - Trigger target when run by a Trigger rule
//   - TitleBar Button owner when run by a TitleBar Button
//   - Jump List owner when run from a Taskbar Jump List
//   - Currently focused window if none of these match
public static class DisplayFusionFunction
{
    public static void Run(IntPtr windowHandle)
    {
        // set cs:go path
        string csgoPath = "E:\\Games\\Steam\\steamapps\\common\\Counter-Strike Global Offensive\\csgo.exe";
        
        //set up nircmd path (http://www.nirsoft.net/utils/nircmd.html)
        string nircmdPath = "E:\\Applications\\nircmd\\nircmd.exe";
        
        const int waitForever = 0;

        // load a monitor profile with the desired resolution settings
        BFS.DisplayFusion.LoadMonitorProfile("Gaming");

        // set system volume to 70% (65535 = 100% volume for Windows 10)
        BFS.Application.Start(nircmdPath, "setsysvolume 45880");

        // start cs:go via steam (required to get verified by VAC)
        BFS.Application.Start("steam://rungameid/730", "");

        // wait 5 seconds, steam usually takes some seconds before cs:go is loaded	
        bool ok = BFS.General.ThreadWait(5000);

        // return to work-mode when cs:go exits
        uint csgoAppId = BFS.Application.GetAppIDByFile(csgoPath);
        BFS.Application.WaitForExitByAppID(csgoAppId, waitForever);

        // set system volume to 30% (65535 = 100% volume for Windows 10)
        BFS.Application.Start(nircmdPath, "setsysvolume 19880");

        // load work monitor profile
        BFS.DisplayFusion.LoadMonitorProfile("Work");
    }
}