Achievement Hunter sheetSheet Note N2 · Sheet 04 TR / EN

Note N2 · Achievement Hunter

DETECTING THE RUNNING GAME

Detecting the running game without Steam's Web API: appmanifest files and window titles

Sheet
ACHIEVEMENT HUNTER
Topic
Java · JNA · Steam
Source
service/GameScannerService.java
Date
2026-11-12
Reading
2 min

Short answer: build the list of installed games from Steam's own files on disk: find the Steam folder in the registry, every library from libraryfolders.vdf, and each game's name and AppID from appmanifest_*.acf in each library. To tell which one is running, look at the foreground window first, then all visible windows; match the title against installed game names and rule out known classes such as browsers and the file explorer.

01Why not the Web API

The Steam Web API can tell which game the user is playing, but it needs a key, a network request and a public profile. The desktop app already runs on the computer where the game runs; what it looks for is on disk and in the window manager. A path with no network is both faster and cleaner for privacy.

02Installed games

  • The Steam folder comes from the registry: current user first, then machine-wide, then the WOW6432Node key on 64-bit Windows.
  • steamapps/libraryfolders.vdf lists every library folder; games can be on different drives.
  • Each library's appmanifest_<appid>.acf gives the game's name, AppID and install folder.

The scan runs once, on a separate thread, and its result is cached. When the scan finishes, polling for the running game starts.

03The running game

// 1. The foreground window
HWND fg = User32.INSTANCE.GetForegroundWindow();
int appId = checkWindowForGame(fg, installedGames);
if (appId > 0) return appId;

// 2. Every visible window
User32.INSTANCE.EnumWindows((hWnd, arg) -> {
    if (!User32.INSTANCE.IsWindowVisible(hWnd)) return true;
    int id = checkWindowForGame(hWnd, installedGames);
    if (id > 0) { found[0] = id; return false; }   // found, stop
    return true;
}, null);

Checking the foreground window first solved the game-switching problem: an old game's window left hanging in the background was blocking detection of the newly started one.

04Avoiding false matches

A game's name in a window title isn't enough; with the game's wiki page open in a browser, the title contains the name too. The window class is checked and known non-game classes are ruled out: the file explorer (CabinetWClass), all Chromium-based apps (Chrome, Edge, Discord, VS Code, Electron), Firefox, the desktop and the taskbar. Windows with an empty title are never considered.

An exception thrown inside a native window callback could bring down the JVM, so the callback body catches its own errors and keeps scanning.

05Polling and events

The running game is checked every 4 seconds (a fixed-delay timer; a long run doesn't overlap the next). When the game changes, the app state is updated first, then the event is published; newly opened windows see the right AppID. The overlay that receives the event starts the Steam client library (steamworks4j) itself; the detection service doesn't restart it again. Starting it from two places was creating a race condition.

→More notes from this project

—End of notewritten by MUHAMMEDPYZ