Last active
March 7, 2025 17:15
-
-
Save dhayab/cd8db998437081fdf068c959f50f8afe to your computer and use it in GitHub Desktop.
Gives the option to launch Steam either in Big Picture or minimized on startup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;@Ahk2Exe-AddResource steam_logo.png, steam_logo.png | |
#Requires AutoHotkey v2.0+ | |
; --- Configuration --- | |
DryRun := false | |
DelaySeconds := (A_Args.Length > 0 && A_Args[1] != "") ? Number(A_Args[1]) : 5 | |
SteamPath := "C:\Program Files (x86)\Steam\Steam.exe" | |
LogoFile := LoadImageFromResource("steam_logo.png") | |
LogoSize := 200 | |
; --- End Configuration --- | |
; --- GUI Setup --- | |
UI := Gui("-Caption +ToolWindow") | |
UI.BackColor := "Black" | |
WinSetTransColor("Black", UI) | |
UI.SetFont("s24 cWhite", "Arial") | |
Dpi := A_ScreenDPI / 96 | |
ScreenWidth := A_ScreenWidth / Dpi | |
ScreenHeight := A_ScreenHeight / Dpi | |
CenterX := ScreenWidth / 2 | |
CenterY := ScreenHeight / 2 | |
pic := UI.AddPicture("w" LogoSize " h" LogoSize " x" (CenterX - (LogoSize // 2)) " y" (CenterY - LogoSize) " +BackgroundTrans", LogoFile) | |
countdownText := UI.AddText("x0 w" ScreenWidth " y+0", "Launching Big Picture in " DelaySeconds " seconds...") | |
countdownText.Opt("Center vCountdownText") | |
cancelText := UI.AddText("x0 w" ScreenWidth " y+10", "press A on the controller to skip the countdown`nor move your mouse to launch minimized") | |
cancelText.SetFont("s12 cWhite", "Arial") | |
cancelText.Opt("Center") | |
UI.Show("x0 y0 w" A_ScreenWidth " h" A_ScreenHeight) | |
Esc::ExitApp() | |
Joy1::OpenSteam(true, 1000) | |
; --- End GUI Setup --- | |
; --- Countdown Logic --- | |
Sleep(500) | |
MouseGetPos(&StartMouseX, &StartMouseY) | |
StartTime := A_TickCount | |
SetTimer(Tick, 200) | |
Tick() { | |
ElapsedTime := (A_TickCount - StartTime) / 1000 | |
RemainingSeconds := Ceil(DelaySeconds - ElapsedTime) | |
if (MouseMoved()) | |
{ | |
OpenSteam(false, 1000) | |
} | |
if (RemainingSeconds <= 0) | |
{ | |
OpenSteam(true, 5000) | |
} | |
countdownText.Value := "Launching Big Picture in " RemainingSeconds " " (RemainingSeconds > 1 ? "seconds" : "second") "..." | |
} | |
; --- End Countdown Logic --- | |
OpenSteam(BigPictureMode, Delay) { | |
if (BigPictureMode) | |
{ | |
Args := "-bigpicture" | |
Message := "Launching Big Picture now..." | |
} else { | |
Args := "-nochatui -nofriendsui -silent" | |
Message := "Launching minimized..." | |
} | |
SetTimer(Tick, 0) | |
countdownText.Value := Message | |
cancelText.Value := "" | |
if (!DryRun) | |
{ | |
Run(SteamPath " " Args) | |
Sleep(Delay) | |
UI.Destroy() | |
ExitApp() | |
} | |
} | |
MouseMoved() { | |
MouseGetPos(&CurrentMouseX, &CurrentMouseY) | |
return Abs(CurrentMouseX - StartMouseX) > 10 || Abs(CurrentMouseY - StartMouseY) > 10 | |
} | |
/** | |
* Bundles a resource file into the compiled script | |
* @param ResourceName | |
* @param {Integer} ReturnType | |
* @returns {String || Integer} | |
* ReturnType := -1 >> Returns <hBitmap> as an integer | |
* ReturnType := 0 >> Returns a string in the format of `HBMITMAP:<hBitmap>` | |
* ReturnType := 1 >> Returns a string in the format of `HBMITMAP:*<hBitmap>` (allows reusing the same hBitmap) | |
* @see https://www.autohotkey.com/boards/viewtopic.php?p=585650&sid=aefb133f798271a3b99e3d034d0522cf#p585650 | |
*/ | |
LoadImageFromResource(ResourceName, ReturnType := 0) { | |
if (!A_IsCompiled) { | |
return ResourceName | |
} else { | |
hModule := DllCall("GetModuleHandle", "Ptr", 0, "Ptr") | |
Resource := DllCall("FindResource", "Ptr", hModule, "Str", ResourceName, "UInt", RT_CDATA := 10, "Ptr") | |
if (!Resource) { | |
throw ValueError("Resource not found", -1, ResourceName) | |
} | |
ResourceSize := DllCall("SizeofResource", "Ptr", hModule, "Ptr", Resource) | |
ResourceData := DllCall("LoadResource", "Ptr", hModule, "Ptr", Resource, "Ptr") | |
hGdip := DllCall("Kernel32.dll\LoadLibrary", "Str", "Gdiplus.dll", "Ptr") | |
pStream := DllCall("Shlwapi\SHCreateMemStream", "Ptr", ResourceData, "UInt", ResourceSize, "Ptr") | |
GdipStartup := Buffer((A_PtrSize * 2) + 8, 0), NumPut("UInt", 1, GdipStartup) | |
DllCall("Gdiplus.dll\GdiplusStartup", "Ptr*", &pToken := 0, "Ptr", GdipStartup, "Ptr", 0) | |
DllCall("Gdiplus.dll\GdipCreateBitmapFromStreamICM", "Ptr", pStream, "Ptr*", &pBitmap := 0) | |
DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "Ptr", pBitmap, "Ptr*", &hBitmap := 0, "UInt", 0) | |
DllCall("Gdiplus.dll\GdipDisposeImage", "Ptr", pBitmap) | |
DllCall("Gdiplus.dll\GdiplusShutdown", "Ptr", pToken) | |
DllCall("Kernel32.dll\FreeLibrary", "Ptr", hGdip) | |
ObjRelease(pStream) | |
return ReturnType = -1 ? hBitmap : "HBITMAP:" (ReturnType ? "*" : "") hBitmap | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment