I want to pause, suspend key when I m not on my game tab (roblox)

Ask gaming related questions (AHK v1.1 and older)

Rohwedder
Posts: 7824
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: I want to pause, suspend key when I m not on my game tab (roblox)

Post by Rohwedder » 08 Dec 2023, 04:07

Hallo,
see https://www.autohotkey.com/docs/v1/Program.htm#tray-icon
can Window Spy clearly recognize this state?
(An AI that monitors the game and the player via webcam will not be available until Autohotkey v3)

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

Re: I want to pause, suspend key when I m not on my game tab (roblox)

Post by mikeyww » 12 Dec 2023, 09:33

Something like this may work as a separate script.

Pause and suspend another script

Code: Select all

; Dedicated script to pause & suspend another script
#Requires AutoHotkey v1.1.33
#SingleInstance
; --------------------------------------------------------
scriptToStop := A_ScriptDir "\stopMe.ahk"
gameWinTitle := "Roblox"
; --------------------------------------------------------
DetectHiddenWindows On
WinWait % scriptToStop " ahk_class AutoHotkey"
Loop {
 WinWaitNotActive % gameWinTitle            ; Wait for game to become inactive
 stopScript(scriptToStop, "Suspend")        ; Suspend ON
 stopScript(scriptToStop, "Pause"  )        ; Pause ON
 WinWaitActive % gameWinTitle               ; Wait for game to become active
 stopScript(scriptToStop, "Suspend", False) ; Suspend OFF
 stopScript(scriptToStop, "Pause"  , False) ; Pause OFF
}

stopScript(script, suspendOrPause, tf := True) {  ; Suspend or pause another script
 ; script         = Full path to the script to suspend or pause
 ; suspendOrPause = SUSPEND or PAUSE (a string)
 ; tf             = True or False (1 or 0)
 Static WM_COMMAND      := 0x0111
      , ID_FILE_PAUSE   := 65403
      , ID_FILE_SUSPEND := 65404
 DetectHiddenWindows On
 If WinExist(script " ahk_class AutoHotkey") {    ; Proceed if script is running
  If (suspendOrPause = "Suspend")
       ps := ID_FILE_SUSPEND, isStopped := isSuspended(script)
  Else ps := ID_FILE_PAUSE  , isStopped := isPaused(script)
  If !tf != !isStopped
   SendMessage WM_COMMAND, ps
 }
}

isSuspended(script) {
 ; https://stackoverflow.com/questions/14492650/check-if-script-is-suspended-in-autohotkey
 Static ID_FILE_SUSPEND  := 65404
 DetectHiddenWindows On
 If hWnd := WinExist(script " ahk_class AutoHotkey") {          ; Proceed if script is running
  mainMenu  := DllCall("GetMenu", "Ptr", hWnd)                  ; Get the menu bar
  fileMenu  := DllCall("GetSubMenu", "Ptr", mainMenu, "Int", 0) ; Get the File menu
  state     := DllCall("GetMenuState", "Ptr", fileMenu, "UInt", ID_FILE_SUSPEND, "UInt", 0)
  DllCall("CloseHandle", "ptr", fileMenu), DllCall("CloseHandle", "ptr", mainMenu)
  Return state >> 3 & 1                                         ; Get the checkmark flag
 }
}

isPaused(script) {
 ; https://www.autohotkey.com/board/topic/90563-a-minimalisitc-script-to-identify-if-a-script-is-paused/
 Static WM_ENTERMENULOOP := 0x211
      , WM_EXITMENULOOP  := 0x212
 DetectHiddenWindows On
 If hWnd := WinExist(script "ahk_class AutoHotkey") {
  SendMessage WM_ENTERMENULOOP
  SendMessage WM_EXITMENULOOP
  hMenu := DllCall("GetMenu", "UInt", hWnd)
  hMenu := DllCall("GetSubMenu", "UInt", hMenu, "Int", 0)
  Return DllCall("GetMenuState", "UInt", hMenu, "UInt", 4, "UInt", 0x400) & 0x8 != 0
 }
}

Post Reply

Return to “Gaming Help (v1)”