Detect that I'm playing a game Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
haomingchen1998
Posts: 174
Joined: 20 Feb 2023, 16:37

Detect that I'm playing a game

Post by haomingchen1998 » 30 May 2023, 19:56

I saw some people got banned from just having ahk script running in the background while playing a game, I know this is unlikely, but I don't want to take any risk. So I'm looking for a universal solution for detecting that I'm playing ANY game, and then close all the ahk scripts. One idea that I have is when gpu load > 50 and the current active window is fullscreen mode, then close all ahk scripts. I plan to use NVIDIA NVML script to detect gpu load, but it seems like it only works with autohotkey v2. Are there any other ways to detect GPU load? Or is there an easier solution that I'm not thinking about, thanks!

Code: Select all

#Persistent
SetTimer, CheckGPUandWindow, 1000 ; check every 1000ms (1 second)

CheckGPUandWindow:
    GPULoad := GetGPULoad()
    if (GPULoad > 50) {
        WinGet, activeWindowID, ID, A
        WinGetPos, X, Y, Width, Height, ahk_id %activeWindowID%
        if (X = 0 and Y = 0) {
            SysGet, ScreenWidth, 0
            SysGet, ScreenHeight, 1
            if (Width = ScreenWidth and Height = ScreenHeight) {
                 ; now close all AutoHotkey scripts
            }
        }
    }
return

GetGPULoad() {
    ; code to get GPU load goes here
    ; return the GPU load as a percentage (0-100)
}

User avatar
mikeyww
Posts: 27107
Joined: 09 Sep 2014, 18:38

Re: Detect that I'm playing a game  Topic is solved

Post by mikeyww » 30 May 2023, 20:20

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance
GroupAdd games, ahk_exe notepad.exe
GroupAdd games, ahk_exe chrome.exe
WinWaitActive ahk_group games
SoundBeep 1500
DetectHiddenWindows On
WinGet ahk, List, ahk_class AutoHotkey
Loop % ahk
 If (ahk%A_Index% != A_ScriptHwnd)
  WinClose % "ahk_id" ahk%A_Index%
ExitApp

Post Reply

Return to “Ask for Help (v1)”