Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

Ask gaming related questions
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

05 Aug 2020, 13:13

If you don't want that extra Enter's being hit omit if n=4 { to including closing curly bracket } and else word.

You dont report if

Code: Select all

Tilde:= "{~}"
 Send, % Tilde
works in the previous script.
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

06 Aug 2020, 11:31

ok so this one works now , except that i still need said function for it , that being pause on game focus loss and continue execution from paused state and exit ahk on completion

here>

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;CoordMode, Mouse, Client ; not needed
WinWait, % Title:= "Shadow Warrior 2 ahk_exe ShadowWarrior2.exe",, 30
IfWinNotActive, % Title
    WinActivate, % Title
WinWaitActive, % Title,, 30
;Sleep, 5000 ; you said 30 sec. ???
Sleep, 5000 ; 30 sec. ; unclear!!!
Send, {Enter} 
sleep 300
Tilde:= "^{~}"
Send, % Tilde
Sleep, 300 ; some time betwixt the entries (may vary form 0 to 500 ms or more)
Send, r_weapon_fov 65
sleep 300
Send, {Enter} 
Sleep, 300 ; some time betwixt the entries (may vary form 0 to 500 ms or more)
Send, r_fog_local_lights 0
Send, {Enter} 
sleep, 300
Send, a_lods 0
Send, {Enter} 
sleep, 300
Send, % Tilde
ExitApp
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

06 Aug 2020, 12:30

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

St:= ["^{~}", "r_weapon_fov 65", "r_fog_local_lights 0", "a_lods 0", "^{~}"], n:= 0

WinWait, % Title:= "Shadow Warrior 2 ahk_exe ShadowWarrior2.exe",, 30
WinActivate, % Title
WinWaitActive, % Title,, 30
Sleep, 5000
Send, {Enter}
#Persistent
SetTimer, InputData, 300
Return

InputData:
    WinActivate, % Title
    KeyWait, Alt
    KeyWait, Ctrl
    KeyWait, LButton
    BlockInput, On
    If WinActive(Title) {
        Sleep, 300
        Send, % St[++n]
        if (n>=St.Length())
            ExitApp
        Send % "{Enter " (n=1? 0: 1) "}"
    }
    BlockInput, Off
Return

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

St:= ["{~}", "messagemode 1", "g_infiniteammo 1", "{~}", "{~}", "ai_death_FadeDelay 60000"
    , "breakable_NoFadeAndRemove 1", "gore_neverFadeAndRemove 1", "corpseManager_MaxTime 60000"
    , "ai_maxCorpses 60", "corpseManager_MaxEntities 128", "gore_maxLivingGoreEnts 5000", "g_bloodspherescale 35f"
    , "g_gorebloodsphereexpanddistance 75f", "encounterscript_globalmaxai 60", "decal_maxdecalsinradius 40"
    , "decal_maxdecalgroupingradius 400.0f", "g_goresplashjointsused 32", "r_decalclusteringnumdecalsperjob 48"
    , "g_breakabledebugdecals 1", "r_rendergatherdecalsgranularity 32", "g_breakablefloorsplatfromceiling 1"
    , "r_decalLifetimeMultiplier 12", "r_decalDistanceFadeMultiplier 7", "r_detailDistance 25000"
    , "r_decalPixelThresholdFadeStart 200", "r_decalPixelThresholdFadeEnd 180", "r_detailFadeDistMax 24000"
    , "r_flaresQuality 0", "r_foliageStartFadeDist 20000", "r_foliageSmallFadeDistMax 25000"
    , "r_foliageBigFadeDistMax 25000", "r_lightDistanceFadeMultiplier 7", "r_shadowFadeRangeScale 7"
    , "r_shadowLODProjectionSizeFactor 0.25", "r_shadowPlayerLOD 0", "g_showPlayerShadow 1", "p_showFootstepParticles 1"
    , "image_BCCompressionQuality 0", "decal_ForceFadeOutDuration 100000", "r_decalDistanceExtendedFadeStart 6000"
    , "r_staticTransparencyFadeMaxDist 6000", "r_staticTransparencyFadeStartDist 5900", "dp_fxLimitThirdPerson 0"
    , "r_shadowsDistanceFadeMultiplier 7", "vt_lodBias -2", "hands_FovScale 0.95", "hands_offsetx .13"
    , "hands_offsetz -.03", "hands_offsetpitch 2", "hands_offsetyaw -2", "{~}"], n:= 0

WinWait, % Title:= "DOOMx64vk ahk_exe DOOMx64vk.exe",, 30
WinActivate, % Title
WinWaitActive, % Title,, 30
Sleep, 30000
#Persistent
SetTimer, InputData, 300
Return

InputData:
    WinActivate, % Title
    KeyWait, Alt
    KeyWait, Ctrl
    KeyWait, LButton
    BlockInput, On
    If WinActive(Title) {
        Send, % St[++n]
        Sleep 300
        Send % "{Enter " ((n=1||n=St.Length())? 0: 1) "}"
        if (n= 4) {
            Sleep, 300
            Send, {Enter}
            Sleep, 300
            Send, {Enter}
            BlockInput, Off
            Sleep, 40000
        } Else Sleep 300
        if (n>=St.Length())
            ExitApp
    }
    BlockInput, Off
Return
There were three edit/typo bugs in the St Array! It's sad you didn't noticed it!
Last edited by rommmcek on 06 Aug 2020, 17:27, edited 1 time in total.
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

06 Aug 2020, 15:31

shall check it out my dude , thanks as usual

p.s... notice? lols hell im having a hard time getting shit to run proper as is lols :(
Last edited by tobsto occupied on 07 Aug 2020, 08:04, edited 1 time in total.
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

07 Aug 2020, 08:01

workin pretty grand my dude , thanks for both , finally!!!


next issue i have is with the batchfile regarding cpu threshold set and memory threshold , from what i understand is if either both or one or the other are below said threshold itll exit the game , well currently that dont work heres it again>

Code: Select all

@echo OFF
set VK_LAYER_PATH="" "DOOM;%VK_LAYER_PATH%"
set VK_INSTANCE_LAYERS=VK_LAYER_reshade
@start "" "DOOMx64vk.exe" +devMode_Enable 1 +com_skipIntroVideo 1 +exec DOOMConfig.cfg +com_skipKeyPressOnLoadScreens 1
::========= Set cpuThreshold [%] and memThreshold [according to displayed value in Cmd window] =========
set /a cpuThreshold=19        & set /a memThreshold=1350000
::initialize vars                            and set process_name:
set /a low=0 & setlocal enableDelayedExpansion & set process_name=DOOMx64vk.exe
set pn=%process_name:.exe=%
::==================================================================
::Launch the App
tasklist | findstr /i %process_name% > nul && start /min "" "easy access to campaign.ahk"
::Get NumberOfCores
for /f "tokens=*" %%f in ('wmic cpu get NumberOfCores /value ^| find "="') do set %%f
:CheckCpuAndMem
set /a process_snapshot=0 & set /a memUsg=0
::CPU
for /f skip^=2^ tokens^=3^ delims^=^" %%p in (
    'typeperf "\Process(%pn%)\%% Processor Time" -sc 1') do for /f "tokens=1 delims=." %%a in (
    "%%p") do set /a process_snapshot=%%a/%NumberOfCores%
if %process_snapshot% LSS %cpuThreshold% (set /a low+=1) else (set /a low=0)
::Mem
for /f "tokens=5" %%p in (
  'tasklist ^|findstr %process_name%') do for /f "tokens=1,2,3 delims=." %%a in ("%%p") do set /a memUsg=%%a%%b%%c/1000
if %memUsg% lss %memThreshold% (set /a low+=1) else (set /a low=0)
::echo feedback
@echo process_snapshot: %process_snapshot%, memUsage: %memUsg%;    LowCpuAndMem: %low%
::12 checks (Cpu & Mem) times 3 sec timeout plus processing delay yields ca 30 sec
if %low% GEQ 12 taskkill /F /T /IM %process_name% & goto RUNNING
timeout /t 3
tasklist|findstr %process_name% > nul && GOTO CheckCpuAndMem
:RUNNING
tasklist|findstr %process_name% > nul && (
    taskkill /F /T /IM cheatengine-x86_64.exe) & taskkill /F /T /IM Werfault.exe &
    exit /b
timeout /t 1
GOTO RUNNING
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

10 Aug 2020, 04:08

tobsto occupied wrote:
07 Aug 2020, 08:01
from what i understand is if either both or one or the other are below said threshold itll exit the game
Wrong! Since we are using the same variable "low" for both thresholds, the game will exit only if both preset values are greater then retrieved values for memory and CPU usage. If you want the game to exit at only one of them fulfilling the condition then you have to separate the variables to e.g.: "lowMem" for memory and "lowCPU" for CPU.
Further below you have then to double the "if statement" for each variable, but lower the count form 12 to 6 of course.

P.s.: It seems you edited the script. Forth and third last lines are inconsistent. It may work or may not work...
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

11 Aug 2020, 14:44

well it works sometimes but not when i need it too in a certain game , for example the music is still running but the games screen is frozen and i have to alt tab delete out and exit the game per taskmanager , a solution would be to have a gpu threshold , from what ive red this would require nvidia-smi commands ,


https://superuser.com/questions/1507148/how-to-kill-all-processes-using-a-given-gpu


not sure if possible ?
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

13 Aug 2020, 06:26

About PowerShell and specially GPU I'm still more in the dark then for Cmd, CPU and Mem! You have to find a working similar script other wise I can't help you, it would take to much time with an uncertain outcome!

You don't show your partially working script. I made several bugs in the past, do you think yours is bug free?
Besides existing script can be modified to monitor CPU and Mem for multiple processes, wich can serve for later action if you can figure out the pattern...
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

13 Aug 2020, 11:11

well me figuring out a pattern lols , not too confident in that , and no i dont think mine is bug free if you mean the batch

concerning finding a working gpu monitoring script that exits on certain threshold ...no luck so far only find was above link for now ...damn, hope ill find something not easy at all finding such specific scripts
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

17 Aug 2020, 15:15

nvidia-smi is a .exe app. It can be run from Cmd too. Save below code into .bat file and edit the path if necessary. All this of course if you have Nvidia graphic card. It depends on the card itself how much info will be shown. My is not very good I guess (see pic).

Code: Select all

@echo off
cd C:\Program Files\NVIDIA Corporation\NVSMI\
nvidia-smi
pause
Exit /b
If shown info will be sufficient then we can extract the data, but Windows OS seems to have some limits...
Attachments
NvidiaData.png
NvidiaData.png (11.31 KiB) Viewed 558 times
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

20 Aug 2020, 07:13

did the batch , says :

'nvidia-smi' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . .





and yes the directory is correct and exists
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

20 Aug 2020, 07:20

this would be the solution i found

https://stackoverflow.com/questions/57100015/how-do-i-run-nvidia-smi-on-windows

Make a shortcut that runs nvidia-smi and refreshes periodically

Follow the above steps under 'To find your exact location'.
Right click on nvidia-smi.exe (it may just say nvidia-smi in the viewpane) and choose create a shortcut. It will likely tell you that you can't create a shortcut here, and ask if you want to put it on your desktop. Hit yes.
Now, on the desktop, right click on the shortcut you have just created, hit properties, and Under Shortcut > Target modify the string path to include -l < time you want it to refresh >.
For example, modify:

C:\Windows\System32\DriverStore\FileRepository\nvdm*\nvidia-smi.exe
to

C:\Windows\System32\DriverStore\FileRepository\nvdm*\nvidia-smi.exe -l 5
Then hit "Apply", and then "OK".

In this example, when you open the shortcut, it will keep the command prompt open and allow you to watch your work as nvidia-smi refreshes every five seconds.
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

20 Aug 2020, 07:22

ok so gpu usage shows under N/A
Default

on the very right right under GPU-Util Compute M.
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

25 Aug 2020, 20:10

Here is extraction code for the data. It works for me (code for me in the spoiler).
You have to determine if the data provide some usable info when the game works vs. game crashes. Then we can take action...

Code: Select all

@echo OFF
cd "C:\Program Files\NVIDIA Corporation\NVSMI\"
:GPU
for /f skip^=8^ tokens^=1-3^ delims^=^| %%a in ('"nvidia-smi.exe"') do (
    for /f "tokens=1-6 delims= " %%g in ("%%a") do set u=%%g & set v=%%h) & set w=%%j) & (
    for /f "tokens=1-3 delims= " %%g in ("%%b") do set x=%%g & set y=%%i) & (
    for /f "tokens=1-2 delims= " %%g in ("%%c") do set z=%%g) & goto :breakForLoop
:breakForLoop
rem set /a u+=0 & set /a v+=0 & set /a w+=0 & set /a x+=0 & set /a z+=0
set /a u=u & set /a v=v & set /a w=w & set /a x=x & set /a z=z
echo %u%, %v%, %w%, %x%, %y%, %z%
rem pause
timeout /t 5
goto GPU
[Edit] Added quotes to cd command and changed skip to 8 (I think you didn't post complete pic of GPU info.
Spoiler
Last edited by rommmcek on 27 Aug 2020, 09:26, edited 1 time in total.
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

26 Aug 2020, 08:14

shall check it out my dude thanks in advance you rock

btw what do i try out the first or the edited one?
User avatar
rommmcek
Posts: 1123
Joined: 15 Aug 2014, 15:18

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

26 Aug 2020, 15:04

The best this one: C:\Windows\System32\DriverStore\FileRepository\nvdm*\nvidia-smi.exe -l 5. It already works for you and shows some processes too which should you observe if you recognize some from your game.
User avatar
tobsto occupied
Posts: 141
Joined: 20 Feb 2020, 09:34
GitHub: washingleavesandthen

Re: Request for a script that autostops commands etc. on app focus loss and continue on refocus from where it left off

27 Aug 2020, 08:43

no mine is the same directory of course>
C:\Program Files\NVIDIA Corporation\NVSMI\


but as said if i run the cd C:\Program Files\NVIDIA Corporation\NVSMI\
command i get a not recognized error as explained in previous post, i had to add the short to a shortcut created off the exe for it to work

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 17 guests