Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(enhancement) On windows, you can get the running app without using the Steam API #7

Open
elmisback opened this issue Aug 12, 2024 · 0 comments

Comments

@elmisback
Copy link

Even when the user is offline, the running Steam app id appears in the registry under HKEY_CURRENT_USER\Software\Valve\Steam\RunningAppID. It can be checked with Python like this:

import winreg

def get_running_app_id():
    try:
        # Open the Steam registry key
        steam_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Valve\Steam")
        
        # Try to get the RunningAppId value
        app_id, _ = winreg.QueryValueEx(steam_key, "RunningAppId")
        
        # Close the registry key
        winreg.CloseKey(steam_key)
        
        return app_id
    except FileNotFoundError:
        return None
    except Exception as e:
        return f"Error: {str(e)}"

if __name__ == "__main__":
    app_id = get_running_app_id()
    if app_id:
        print(f"Running App ID: {app_id}")
    else:
        print("No game is currently running or the registry key was not found.")

Game details can then be obtained via the public Steam store:

details = requests.get(f"https://store.steampowered.com/api/appdetails?appids={app_id}").json()[str(app_id)]['data']

details['name'] # gives the title of the running game
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant