• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 10:49
CET 16:49
KST 00:49
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
$21,000 RyongYi Cup Season 3 announced (Jan 22-Feb 7)4Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns6[BSL21] Non-Korean Championship - Starts Jan 103SC2 All-Star Invitational: Jan 17-1822Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises3
StarCraft 2
General
Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns SC2 All-Star Invitational: Jan 17-18 Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises Chinese SC2 server to reopen; live all-star event in Hangzhou Starcraft 2 Zerg Coach
Tourneys
$21,000 RyongYi Cup Season 3 announced (Jan 22-Feb 7) WardiTV Winter Cup WardiTV Mondays SC2 AI Tournament 2026 OSC Season 13 World Championship
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 507 Well Trained Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes Mutation # 504 Retribution
Brood War
General
I would like to say something about StarCraft BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest Data analysis on 70 million replays
Tourneys
[Megathread] Daily Proleagues [BSL21] Grand Finals - Sunday 21:00 CET [BSL21] Non-Korean Championship - Starts Jan 10 SLON Grand Finals – Season 2
Strategy
Game Theory for Starcraft Simple Questions, Simple Answers Current Meta [G] How to get started on ladder as a new Z player
Other Games
General Games
General RTS Discussion Thread Nintendo Switch Thread Awesome Games Done Quick 2026! Stormgate/Frost Giant Megathread Should offensive tower rushing be viable in RTS games?
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Trading/Investing Thread The Big Programming Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced
Blogs
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
Psychological Factors That D…
TrAiDoS
James Bond movies ranking - pa…
Topin
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2564 users

An Automatic SC2 Game Start Switcher

Forum Index > SC2 General
Post a Reply
1 2 Next All
Zamiel
Profile Blog Joined August 2008
United States211 Posts
Last Edited: 2013-02-28 06:25:32
February 26 2013 21:44 GMT
#1
The StarCraft II Automatic Game Start Switcher
Current version: 0.2
Last updated: Feb. 27th, 2012

+ Show Spoiler [Version history] +
Feb. 27 - v0.2 - R1CH told me to rewrite the program in C#, so I did. It's a lot cleaner now (it doesn't use exec calls to reg.exe or any VBScript).
Feb. 26 - v0.1 - The first version, written in Java.


The problem:
- In between ladder games, I often alt-tab out and browse Reddit. However, I often get distracted and forget to alt-tab back in time, missing out on the first couple seconds of the game.

Existing solution #1 and why it sucks:
- When StarCraft II is set to fullscreen mode, Windows will automatically switch to the loading screen when it begins the map loading procedure.
- This is only a halfway solution, since the loading process can take many minutes to complete. This is especially true when playing particular arcade maps with many players; I should not have to be staring at the screen waiting for the game to load for 5+ minutes at a time.
- In windowed fullscreen mode, this functionality is not present at all. Many people play in windowed fullscreen mode since it is much easier to alt-tab in and out of the game. With some exceptions, windowed fullscreen is also necessary if you want to stream.

Existing solution #2 and why it sucks:
- In the sound part of the options, there is a "Play in Background" checkbox. When this option is selected, StarCraft sounds will still be heard even when you are alt-tabbed out of the game.
- Most StarCraft players disable the in-game music and soften the in-game sounds in order to better hear their own music/Skype. When a game starts, there is hardly any sound whatsoever, just the soft ambient sounds of your workers mining. This is virtually impossible to hear over loud music.
- The countdown timer is generally very loud and can be heard over music. However, this only notifies you to the beginning of the loading of the map, not the actual beginning of the game. To reiterate, the loading process can take many minutes to complete. This is especially true when playing particular arcade maps with many players; I should not have to be staring at the screen waiting for the game to load for 5+ minutes at a time.

My solution:
- I wrote a tiny program to automatically bring the SC2 window into the foreground after a game has finished loading. All you have to do is start the program; you can then minimize the window if you want.

Requirements:
- Windows

Download:
- https://mega.co.nz/#!sdIjzJpQ!TONuu1hxB7k0tmnywErwKWBaK5JIvucedIRRGbLgGIU

Legality:
- This program doesn't read SC2 memory, only the registry entries that the Razer APM peripherals access in order to glow the different colors. Thus, if you use it, you don't have to be worried about being banned for "hacking" or whatnot.

Bugs:
- The game doesn't write the APM to the registry fast enough in order to allow for a completely instant switch. Normally, the in-game timer will read 0:02 by the time the switch occurs. But that's still pretty fast and better than nothing. If anyone knows of a better way, please let me know!
- I've only tested this on my own machine, which is a 64-bit Windows 8. Feel free to provide feedback if it doesn't work for you.

Source (if you want to compile it yourself or see how it works):
+ Show Spoiler [Program.cs] +
using System;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32;

namespace SC2GameStartSwitcher
{
class Program
{
//Import the FindWindow API to find our window
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindowNative(string className, string windowName);

//Import the SetForeground API to activate it
[DllImport("User32.dll", EntryPoint = "SetForegroundWindow")]
private static extern IntPtr SetForegroundWindowNative(IntPtr hWnd);

public static IntPtr FindWindow(string className, string windowName)
{
return FindWindowNative(className, windowName);
}

public static IntPtr SetForegroundWindow(IntPtr hWnd)
{
return SetForegroundWindowNative(hWnd);
}

public static void Activate(string title)
{
//Find the window, using the Window Title
IntPtr hWnd = FindWindow(null, title);
if (hWnd.ToInt32() > 0) //If found
{
SetForegroundWindow(hWnd); //Activate it
}
}

static void Main()
{
int gameState = 0;
RegistryKey MyReg = Registry.CurrentUser.OpenSubKey
("Software\\Razer\\Starcraft2", true);
MyReg.SetValue("APMValue", "1000");

Console.WriteLine("\nWelcome to the StarCraft II Automatic Game Start Switcher.\n");
Console.WriteLine("Game scanning initiated. Feel free to minimize this window.");

while (true)
{
if (gameState == 0) { // in menus
Thread.Sleep(2000); // pause for 2 seconds
if ((int)MyReg.GetValue("StartModule") == 1) {
gameState = 1;
}
} else if (gameState == 1) { // a game is loading
Thread.Sleep(10); // pause for 10 milliseconds
if (!MyReg.GetValue("APMValue").Equals("1000")) {
Activate("StarCraft II");
gameState = 2;
}
} else if (gameState == 2) { // in a game
Thread.Sleep(2000); // pause for 2 seconds
if ((int)MyReg.GetValue("StartModule") == 0) {
gameState = 0;
MyReg.SetValue("APMValue", "1000");
}
}
}
}

}
}


Enjoy!
"Mech is at the store buying groceries and you attack him at home. You burn his house down. And then he comes home and puts out the fire, and then you burn down the grocery store so he can't buy more groceries."
Nuclease
Profile Joined August 2011
United States1049 Posts
February 26 2013 21:48 GMT
#2
I'm currently studying Computer Science in my university studies.

I can say that I'm very impressed with how simple this program is! I haven't looked through all the code yet, but I see no problems with it. I'm gonna try it later today and see how it goes. Thanks for writing this and letting it be known. Cheers!
Zealots, not zee-lots. | Never forget, KTViolet, Go)Space. | You will never be as good as By.Flash, and your drops will never be as sick as MMA.
501TFX
Profile Joined March 2011
Austria345 Posts
February 26 2013 21:51 GMT
#3
Awesome little program!

I know that doesn't really help all that much, but I just wanted to say, SC2 actually does exactly that in fullscreen mode (Just that you get thrown into the loading screen, not the game), but yeah I know, a lot of people play in windowed fullscreen, so this could get pretty handy
Never let your dreams fade, run after them, run until you get them !
dsjoerg
Profile Joined January 2012
United States384 Posts
February 26 2013 21:56 GMT
#4
I had no idea that Starcraft is writing your APM into the registry. Seems to be so that some Razer peripheral can somehow glow based on your APM or something? Very interesting.

I wonder if that APM is just as bugged as the Score Screen APM?

Nicely done
card-carrying grubby fan. developer of GGTracker.
DanTastiX
Profile Joined July 2011
Germany36 Posts
February 26 2013 22:00 GMT
#5
Im using the Starcraft sound in the background, so I will automatically hear when a game starts. Didnt disappoint me until today :p
Zamiel
Profile Blog Joined August 2008
United States211 Posts
Last Edited: 2013-02-26 22:09:44
February 26 2013 22:03 GMT
#6
SC2 actually does exactly that in fullscreen mode (Just that you get thrown into the loading screen, not the game)


Correct, but I think that the default behavior should be to switch when the game has finished loading, as opposed to when it starts loading. This is especially true in Arcade games, since people can often take up to 5+ minutes to load, and there's a significant amount of Reddit that I can consume in that time!

Seems to be so that some Razer peripheral can somehow glow based on your APM or something?


Yes. See http://www.razerzone.com/licensed-and-team-peripherals/starcraft-2-hots
I am fond of Razer for their various eSports sponsorships, but having a mouse that glows different colors based on your APM is probably the most bullshit computer product ever conceived. =)

I wonder if that APM is just as bugged as the Score Screen APM?


I haven't tried, but I would assume that it's the same thing as the in-game APM.

Im using the Starcraft sound in the background, so I will automatically hear when a game starts.


This is true, but I would go as far as to say that most StarCraft plays disable the in-game music and listen to their own.
"Mech is at the store buying groceries and you attack him at home. You burn his house down. And then he comes home and puts out the fire, and then you burn down the grocery store so he can't buy more groceries."
DanTastiX
Profile Joined July 2011
Germany36 Posts
Last Edited: 2013-02-26 22:19:35
February 26 2013 22:19 GMT
#7
Well, Im not talking about the ingame-music, Im talking about the actual sound. I also got the music disabled. Or do you even play without the sounds? Would be quite a pain in the ass for me not having any sound in battles for example.
Horuku
Profile Blog Joined August 2010
United States405 Posts
February 26 2013 22:19 GMT
#8
Is there a reason you made all the methods statics? Also, why do you do reader.readLine() 3 times in a row? Also, use enums instead of numbers to represent your game states :D .

Nit picks really, good job!
d<^^>b
R1CH
Profile Blog Joined May 2007
Netherlands10341 Posts
February 26 2013 22:23 GMT
#9
I'm a bit worried about the performance concerns of spawning 100 reg.exe processes per second, especially from Java. Isn't there a native method you can use to access the registry? Or maybe use C# to avoid all the horrible interop?
AdministratorTwitter: @R1CH_TL
TL+ Member
Zamiel
Profile Blog Joined August 2008
United States211 Posts
Last Edited: 2013-02-26 22:36:13
February 26 2013 22:34 GMT
#10
Well, Im not talking about the ingame-music, Im talking about the actual sound. I also got the music disabled. Or do you even play without the sounds?


I play with the sounds. I see now that you are referring to the "Play in Background" check-box that appears in the sound options. This is not optimal because, during the beginning of a game, there is hardly any sound whatsoever, just the soft ambient sounds of your workers mining. If you are playing loud or complex music, there's no way that you will be able to hear these sounds.

Is there a reason you made all the methods statics?


No.

Also, why do you do reader.readLine() 3 times in a row?


To get the line that specifically has the data that I want. (Type in "reg query HKCU\Software\Razer\Starcraft2 /v APMValue" into a command prompt.)

I'm a bit worried about the performance concerns of spawning 100 reg.exe processes per second, especially from Java. Isn't there a native method you can use to access the registry? Or maybe use C# to avoid all the horrible interop?


Haha, I'll try rewriting it in C#. Give me a few hours. =p
"Mech is at the store buying groceries and you attack him at home. You burn his house down. And then he comes home and puts out the fire, and then you burn down the grocery store so he can't buy more groceries."
DanTastiX
Profile Joined July 2011
Germany36 Posts
February 26 2013 22:46 GMT
#11
Actually I was talking about the Countdown-Noise which is quite catchy in my opinion :D Anyways, I guess this programm can be handy for some people out there.
mousewiz
Profile Joined February 2013
Canada18 Posts
Last Edited: 2013-02-26 22:52:05
February 26 2013 22:48 GMT
#12
*runs off to put a rootkit called "reg" in everyone's download directory*
Well, not really, but exec("notAFullPath") is sketchy as hell. Actually, exec is sketchy as hell, but full paths make it a little better. Edit: Actually I was thinking Java did something that Java probably doesn't do, so download directory would not be sufficient, but it's still definitely exploitable.

I'd also be worried about leaking file descriptors with all your exec calls. You also leak if is.read throws, for example. I'm not sure how big an issue this is on Windows, but I know you're risking trouble on Unixy systems.
Zamiel
Profile Blog Joined August 2008
United States211 Posts
Last Edited: 2013-02-27 06:12:05
February 27 2013 06:09 GMT
#13
Here it is in C# (my first C# program, yay). As R1CH indicated, it's much cleaner this way since it has no exec calls to reg.exe or usage of VBScript at all.

+ Show Spoiler [Program.cs] +
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.Win32;

namespace SC2GameStartSwitcher
{
class Program
{
//Import the FindWindow API to find our window
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindowNative(string className, string windowName);

//Import the SetForeground API to activate it
[DllImport("User32.dll", EntryPoint = "SetForegroundWindow")]
private static extern IntPtr SetForegroundWindowNative(IntPtr hWnd);

public static IntPtr FindWindow(string className, string windowName)
{
return FindWindowNative(className, windowName);
}

public static IntPtr SetForegroundWindow(IntPtr hWnd)
{
return SetForegroundWindowNative(hWnd);
}

public static void Activate(string title)
{
//Find the window, using the Window Title
IntPtr hWnd = FindWindow(null, title);
if (hWnd.ToInt32() > 0) //If found
{
SetForegroundWindow(hWnd); //Activate it
}
}

static void Main()
{
int gameState = 0;
RegistryKey MyReg = Registry.CurrentUser.OpenSubKey
("Software\\Razer\\Starcraft2", true);
MyReg.SetValue("APMValue", "1000");
Console.WriteLine("gameState = 0");

while (true)
{
Thread.Sleep(50); // pause for 50 milliseconds
if (gameState == 0) { // in menus
if ((int)MyReg.GetValue("StartModule") == 1) {
gameState = 1;
}
} else if (gameState == 1) { // a game is loading
if (!MyReg.GetValue("APMValue").Equals("1000")) {
Activate("StarCraft II");
gameState = 2;
}
} else if (gameState == 2) { // in a game
if ((int)MyReg.GetValue("StartModule") == 0) {
gameState = 0;
MyReg.SetValue("APMValue", "1000");
}
}
}
}

}
}


One problem with this kind implementation is that it won't actually switch until 0:02 on the in-game timer, presumably because it takes that long for the APM change to pulse to the registry. So it's not really a bug I can fix.

Now before I go update the OP, R1CH (or whomever), is there a relatively easy way to figure out in-game status in another (better) manner? Hopefully there is a more elegant solution than finding and then reading some random memory offset.
"Mech is at the store buying groceries and you attack him at home. You burn his house down. And then he comes home and puts out the fire, and then you burn down the grocery store so he can't buy more groceries."
R1CH
Profile Blog Joined May 2007
Netherlands10341 Posts
February 27 2013 07:01 GMT
#14
Why not just switch to the game as soon as StartModule changes?
AdministratorTwitter: @R1CH_TL
TL+ Member
Zamiel
Profile Blog Joined August 2008
United States211 Posts
Last Edited: 2013-02-27 07:23:29
February 27 2013 07:21 GMT
#15
StartModule changes to 1 shortly after the game starts to load the map. This is simply unacceptable. To quote myself:

the default behavior should be to switch when the game has finished loading, as opposed to when it starts loading. This is especially true in Arcade games, since people can often take up to 5+ minutes to load
"Mech is at the store buying groceries and you attack him at home. You burn his house down. And then he comes home and puts out the fire, and then you burn down the grocery store so he can't buy more groceries."
Xapti
Profile Joined April 2010
Canada2473 Posts
February 27 2013 09:23 GMT
#16
Why don't you alt-tab a few seconds after the countdown timer reaches 1 or 0?

It's easy to do when you have play sounds in background enabled; just listen for when you're opponent has been found and the timer starts. That's what most people seem to do, and I don't see why anyone would do anything else. Program seems kinda useless
"Then he told me to tell you that he wouldn't piss on you if you were on fire" — "Well, you tell him that I said that I wouldn't piss on him if he was on Jeopardy!"
Scarlett`
Profile Joined April 2011
Canada2392 Posts
February 27 2013 09:26 GMT
#17
On February 27 2013 18:23 Xapti wrote:
Why don't you alt-tab a few seconds after the countdown timer reaches 1 or 0?

It's easy to do when you have play sounds in background enabled; just listen for when you're opponent has been found and the timer starts. That's what most people seem to do, and I don't see why anyone would do anything else. Program seems kinda useless

Music ! I have to leave a lot of ladder games at start because I don't hear sound and tab in 30sec late
Progamer
Rioru
Profile Joined January 2013
11 Posts
February 27 2013 09:52 GMT
#18
Cool program! Thanks for sharing it with the community!
pStar
Profile Blog Joined December 2010
996 Posts
February 27 2013 12:36 GMT
#19
What does this part of the code do?

Process p = rt.exec("reg query HKCU\\Software\\Razer\\Starcraft2 /v APMValue");
Zamiel
Profile Blog Joined August 2008
United States211 Posts
February 27 2013 16:06 GMT
#20
Xapti, please closely read the post directly above yours.

Hi Scarlett!

What does this part of the code do?

Process p = rt.exec("reg query HKCU\\Software\\Razer\\Starcraft2 /v APMValue");


It is basically the same as typing "reg query HKCU\Software\Razer\Starcraft2 /v APMValue" into a command prompt.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/reg.mspx?mfr=true
"Mech is at the store buying groceries and you attack him at home. You burn his house down. And then he comes home and puts out the fire, and then you burn down the grocery store so he can't buy more groceries."
1 2 Next All
Please log in or register to reply.
Live Events Refresh
Next event in 12h 11m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 608
Lowko605
BRAT_OK 129
goblin 49
DivinesiaTV 17
StarCraft: Brood War
Britney 28403
Rain 6889
EffOrt 1947
Stork 826
Shuttle 588
BeSt 506
Mini 206
actioN 193
Rush 171
Barracks 158
[ Show more ]
Dewaltoss 112
Mind 101
Hyun 61
[sc1f]eonzerg 54
JYJ 53
Killer 50
Sea.KH 50
HiyA 50
Larva 47
soO 42
910 25
Rock 17
Yoon 15
scan(afreeca) 11
ajuk12(nOOB) 8
Terrorterran 2
Dota 2
Gorgc6301
qojqva2036
syndereN412
Other Games
Grubby3260
singsing2109
Liquid`RaSZi1267
hiko993
B2W.Neo324
XaKoH 165
ArmadaUGS122
mouzStarbuck83
QueenE78
djWHEAT78
XcaliburYe70
KnowMe63
Liquid`VortiX49
Organizations
Other Games
gamesdonequick25995
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Michael_bg 4
• FirePhoenix1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos4272
• Shiphtur149
Upcoming Events
SOOP
12h 11m
SHIN vs GuMiho
Cure vs Creator
The PondCast
18h 11m
Wardi Open
20h 11m
Big Gabe XPERIONCRAFT
21h 11m
AI Arena Tournament
1d 4h
Sparkling Tuna Cup
1d 18h
WardiTV Invitational
1d 21h
IPSL
2 days
DragOn vs Sziky
Replay Cast
2 days
Wardi Open
2 days
[ Show More ]
Monday Night Weeklies
3 days
WardiTV Invitational
3 days
WardiTV Invitational
4 days
The PondCast
5 days
Liquipedia Results

Completed

Proleague 2026-01-08
WardiTV 2025
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
OSC Championship Season 13
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025

Upcoming

BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
Escore Tournament S1: W4
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Thunderfire SC2 All-star 2025
Big Gabe Cup #3
Nations Cup 2026
Underdog Cup #3
NA Kuram Kup
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.