Gaming Profile Topic is solved

Ask gaming related questions (AHK v1.1 and older)
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 10:10

This is what I have now

Code: Select all

#SingleInstance Force
SetCapsLockState, Off
Loop
{
	FileReadLine, line, Game.txt, %A_Index%
    	MsgBox, Active "%line%"
	IfWinActive, "ahk_exe %line%"
	{
		loop
		{
	 		WinWait, % winTitle := "ahk_exe %line%"
 			MsgBox, High Active
			Run, C:\Windows\System32\Powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
 			WinWaitClose
 			MsgBox, Balance Active
 			Run, C:\Windows\System32\Powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
			Break
		}
		#If WinExist(winTitle)
		; Disable Alt+Tab
		!Tab::Return				
		; Disable Left Windows Key
		LWin::Return
		; CapsLock 
		CapsLock::Return
		#If
	}
}
At the moment it reads my game.txt file yet I am having problem with the output of the file to the WinWait etc
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 10:27

Yes, because expressions require a different syntax.

The following examples could work and may be easier to understand.

Code: Select all

; winTitle := "ahk_exe " line ; := denotes an expression

winTitle    = ahk_exe %line%  ;  = denotes a literal string assignment
; ...
If WinActive(winTitle)        ; Functions use expressions
; ...
WinWait, %winTitle%           ; Commands use literal strings
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 11:10

OK I now have some progress.

Code: Select all

#SingleInstance Force
SetCapsLockState, Off
Loop
{
	FileReadLine, line, Game.txt, %A_Index%
    	winTitle = %line%
	If WinActive := (winTitle)
	{
	 	WinWait, ahk_exe %winTitle%
 		MsgBox, High Active
		Run, C:\Windows\System32\Powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
		WinWaitClose
 		MsgBox, Balance Active
		Run, C:\Windows\System32\Powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
	}
}
#IfWinExist := (winTitle)
MsgBox, Disableing keys
; Disable Alt+Tab
!Tab::Return				
; Disable Left Windows Key
LWin::Return
; CapsLock 
CapsLock::Return
#if
Problem at the moment is the disabling keys it seems constant, If I close notepad it then displays disabling keys message.
apon restarting notepad its not detected.
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 11:38

1. To check whether your window is active, use line 5 from my previous post. The syntax matters; you can't change it to be your own.

2. For #IfWinExist: see viewtopic.php?p=430554#p430554, line 9.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 11:41

yes my window is active and when i close i get the correct responce and power profile change, i then added reload after Winwaitclose. But as i say the disable alt tab etc seems to be constant i only want active when notepad is active, also my file read command is only working from the first line its not reading the second line, so if i put say in game.txt line 1 anno.exe then line 2 notepad.exe its not seeing it. so i need to change to a string i guess not sure my head is starting to fail
Last edited by TrebleTA on 21 Nov 2021, 11:43, edited 1 time in total.
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 11:42

To fix your syntax bugs, follow the two recommendations in my previous post.

You probably need to rework the logic of your loop. It does not currently make sense. Follow the script line by line to see what happens. If your target window is active, then you would not WinWait to see whether that same window exists.

The current loop is infinite, since it has no break. A_Index will continue to increase, starting at 1 and then incrementing by 1 indefinitely (infinitely). You can prove it by displaying its value in the script.

Thus, you have multiple issues to fix before the script will work properly.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 11:52

Thanks my mind is starting to go here, but this is working at moment to a point.

Code: Select all

#SingleInstance Force
SetCapsLockState, Off
Loop
{
	FileReadLine, line, Game.txt, %A_Index%
    	winTitle = %line%
	IfWinActive := (winTitle)
	{
	 	WinWait, ahk_exe %winTitle%
		Run, C:\Windows\System32\Powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
		MsgBox, High Power Profile Actived
		WinWaitClose
 		MsgBox, Balance Power Profile Actived
		Run, C:\Windows\System32\Powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
		Reload
	}
}

I just need to work out why its not reading the 2nd line of the file.
I tried #If WinExist(winTitle) but can not get that to work the disable windows key seems constant so will leave that for now and focus on the above just need to read the file better.
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 12:16

I would try it this way.

Code: Select all

#SingleInstance Force
SetCapsLockState, Off
games = %A_ScriptDir%\games.txt
If !FileExist(games) {
 MsgBox, 48, Error, File not found.`n`n%games%
 Return
} Else FileRead, text, %games%
For each, game in StrSplit(text, "`n")
 GroupAdd, fun, ahk_exe %game%
Loop
{
 WinWait, ahk_group fun                                      ; Wait for the first matching window to exist
 Run, powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
 SoundBeep, 1500
 WinWaitClose, ahk_group fun                                 ; Wait for all matching windows to close
 Run, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
 SoundBeep, 1000
}
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 12:31

Did not work :(
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 12:34

You can post your games.txt file here.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 12:39

all i have is 2 line will post so can see

Code: Select all

Anno1800.exe
Notepad.exe


It worked out to be blank lines that was the problem
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 12:50

So thanks to you I now have it reading correctly, I now need to add the disable alt tab and windows key only when notepad is running also the caplock lower state.

Code: Select all

; Disable Alt+Tab
!Tab::Return				
; Disable Left Windows Key
LWin::Return
; CapsLock 
CapsLock::Return
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 13:08

Ok a bit more testing and running anno1800 it is not detected, I guess it could be path related am not sure, also adding the above for caps lock breaks it. think its time to try more tomorrow
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 13:21

Example:

Code: Select all

#IfWinExist ahk_exe notepad.exe ; Differs from #IfWinActive
!Tab::
LWin::
CapsLock::Return
#IfWinExist
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 13:51

Thanks worked a charm, so why is WinWait not working for Anno1800.exe?
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 14:21

Sorry I have no way to test that at my end. You can debug by displaying each of the game names within the script. If the issue is waiting for the closures, then if anything is still active, in the tray, etc., it will be considered running instead of closed.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 14:39

Thanks so much, It worked out that it was the text format, I now have it as anno1800.exe, notepad.exe and works.

My problem is my Disable Windows key, if I open notepad win key stops. if I use in game it works.

Code: Select all

#SingleInstance Force
SetCapsLockState, Off
games = Games.txt
If !FileExist(games) 
{
	MsgBox, 48, Error, File not found.`n`n%games%
	Return
} 
Else
FileRead, text, %games%
For each, game in StrSplit(text, ",")
GroupAdd, fun, ahk_exe %game%
Loop
{
	WinWait, ahk_group fun                                      ; Wait for the first matching window to exist
	Run, powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
	MsgBox, Hi
	WinWaitClose, ahk_group fun                                 ; Wait for all matching windows to close
	Run, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
	MsgBox, Bal
}
#IfWinExist ahk_group fun 
!Tab::
LWin::
CapsLock::Return
#IfWinExist
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 14:45

Some games require admin mode, and even that is not a guarantee.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 22:12

Hmm I did not think of that, anno1800 is run as admin. I will need the script to run as admin to change gpu clocks too. So will look in to that tomorrow.

Big thank you :beer:
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

22 Nov 2021, 09:14

Hi I did some checked and it was due to admin rights. :)So this part is all working.
I now want to edit the file read string so if I put a name in the game.txt like anno1800.exe1, it will notice the 1 and do a bit different, as will be running a underclock on the GPU also will not be disabling alt tab or windows key.

am thinking I need to read the %games% so be like if %games% = *.exe1 but then need to remove the 1 when checking in winwait

Now am thinking 2 txt files then just repeat what i have? due to having to changed the read string from exe1 to exe in the winwait

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 48 guests