Gaming Profile Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

22 Nov 2021, 09:36

A demonstration is below.

Code: Select all

For each, game in StrSplit(text, ",") {
 lastChar := SubStr(game, 0), thisGame := lastChar = "e" ? game : SubStr(game, 1, -1)
 GroupAdd, fun           , ahk_exe %thisGame%
 GroupAdd, last%lastChar%, ahk_exe %thisGame%
}
F3::Send Normal
#IfWinActive ahk_group last1 ; Group is none of the above
F3::Send Last1
#IfWinActive ahk_group fun   ; Group is none of the above
F3::Send fun
#IfWinActive
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

22 Nov 2021, 10:02

sorry just see your above post thanks
Last edited by TrebleTA on 22 Nov 2021, 10:11, edited 1 time in total.
User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

22 Nov 2021, 10:05

Try as I've shown-- worked in my testing.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

22 Nov 2021, 11:02

Ok what you did worked of course, soon as i added to what i wanted again having problem with the if statement

Code: Select all

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, ",") 
{
	lastChar := SubStr(game, 0), thisGame := lastChar = "e" ? game : SubStr(game, 1, -1)
	GroupAdd, fun           , ahk_exe %thisGame%
	GroupAdd, last%lastChar%, ahk_exe %thisGame%
}
Loop
{	
	If WinExist ("ahk_group".fun)
	{
		WinWait, ahk_group fun                                      ; Wait for the first matching window to exist
		MsgBox, High Performance Power Profile.`n`n                     Activated
		WinWaitClose, ahk_group fun                                 ; Wait for all matching windows to close
		MsgBox, Balance Power Profile.`n`n             Activated
	}
	else If WinExist ("ahk_group".last1)
	{
		WinWait, ahk_group last1                                      ; Wait for the first matching window to exist
		MsgBox,Profile1.`n`n      1111               Activated
		WinWaitClose, ahk_group last1                                 ; Wait for all matching windows to close
		MsgBox,Profile1.`n`n      11111       Activated
	}
}
#IfWinActive ahk_group last1
Return
#IfWinActive ahk_group fun 
!Tab::
LWin::
CapsLock::Return
#IfWinActive
were am i going wrong
User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

22 Nov 2021, 12:27

Function names must always be followed by ( rather than a space.

Check for the "last" group first, because that is the more specialized group. The "fun" group is a superset (contains all).

If the window exists (line 18), then why issue a(nother) command to wait to see whether it exists (line 20)?
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

23 Nov 2021, 09:02

Hi thanks alot that worked I now have this

Code: Select all

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, ",") 
{
	lastChar := SubStr(game, 0), thisGame := lastChar = "e" ? game : SubStr(game, 1, -1)
	GroupAdd, fun           , ahk_exe %thisGame%
	GroupAdd, last%lastChar%, ahk_exe %thisGame%
}
Loop
{	

	If WinExist("ahk_group last1")
	{ 
		MsgBox,Profile1.`n`n      1111               Activated
		WinWaitClose, ahk_group last1                                 ; Wait for all matching windows to close
		MsgBox,Profile1.`n`n      22222       Activated
	}
	else If WinExist("ahk_group fun")
	{
		MsgBox, High Performance Power Profile.`n`n                     Activated
		WinWaitClose, ahk_group fun                                 ; Wait for all matching windows to close
		MsgBox, Balance Power Profile.`n`n             Activated
	}

}
#IfWinActive ahk_group last1
!Tab::
CapsLock::Return

#IfWinActive ahk_group fun 
!Tab::
LWin::
CapsLock::Return
 
#IfWinActive
but having problems with the #IfWinActive ahk_group last1 and #IfWinActive ahk_group fun seem to not work they return the same so lwin:: is always used.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

23 Nov 2021, 09:40

I worked it out i think

Code: Select all

#IfWinActive ahk_group last1	; check if this group is running 
; LWin::Return 				; Disables Left windows Key
!Tab::Return				; Disables Alt Tab

#IfWinActive ahk_group fun	; will do the below always
CapsLock::Return			; Disables capslock

#IfWinActive
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

23 Nov 2021, 10:13

Hi @Mikeyww thank you for all the support I would not of got this far with out you, I have almost finished the code with your help as your see below I have taken the admin check from someone else, but is there anything I have done worng, or should not of done?

Code: Select all

; First, we're calling Window's GetCommandLine() function
; This function retrieves the command-line string for the current process
; We need this string to see if the script is running with the /restart switch
full_command_line := DllCall("GetCommandLine", "str")

; This if-check fires if either of the 2 evaluations are true
; Note the 'not' prefix. This if check fires when 'not' true (false)
; 1) If the script is 'not' running as admin (A_IsAdmin stores whether a script has admin rights)
; OR
; 2) If the full_command_line from above does 'not' contain /restart
;	/Restart is a command line switch that tells the script "this is a restart, not a normal load"
;	This affects some internal things as well as prevents #SingleInstance notifications
; This if-check makes sure that every script is forced to restart with the *RunAs verb
; This ensures the script is always given a chance to launch with elevated rights

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
	; Try is used so that any runtime errors are suppressed
	try
	{
		; The next if check makes sure that .ahk and .exe scripts are restarted correctly

		; Check if the current script is compiled (.exe) or a script (.ahk)
		if A_IsCompiled
			; If compiled, restart using the exe method:
			; CompiledScript.exe [Switches] [Script Parameters]
			; This is covered in the script docs. Link below code.
			Run *RunAs "%A_ScriptFullPath%" /restart
		else
			; If not compiled, restart using the script method:
			; AutoHotkey.exe [Switches] [Script Filename] [Script Parameters]
			Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
	}
	; ExitApp to close this script because we're restarting it with a request for admin rights
	ExitApp
}

; At this point, the script HAS been restarted and is running with admin rights if it can
; MsgBox A_IsAdmin: %A_IsAdmin%`nCommand line: %full_command_line%

#SingleInstance Force		; Forces a Single instance
#Warn 				; Enable warnings to assist with detecting common errors.
#NoEnv				; Recommended for performance and compatibility with future AutoHotkey releases.
;#NoTrayIcon 			; Disable the tray icon of the script
SendMode Input			; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%	; Ensures a consistent starting directory.
SetBatchLines, -1		; Run script at maximum speed
SetCapsLockState, AlwaysOff 	; Disables the caps lock key and defaults off

games = Games.txt 		; Name of my Input file

If !FileExist(games) 
{
	MsgBox, 48, Error, File not found.`n`n%games%
	Return
} 
Else
FileRead, text, %games%
For each, game in StrSplit(text, ",") 
{
	lastChar := SubStr(game, 0), thisGame := lastChar = "e" ? game : SubStr(game, 1, -1)
	GroupAdd, fun           , ahk_exe %thisGame%
	GroupAdd, last%lastChar%, ahk_exe %thisGame%
}
loop
{
	If WinExist("ahk_group last1")
	{ 
		Run, powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
		MsgBox, High Performance Power Profile.`n GPU Overclock`n                     Activated
		WinWaitClose, ahk_group last1                               ; Wait for all matching windows to close
		Run, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
		MsgBox, Balance Power Profile.`n`n        GPU Default     Activated
	}
	If WinExist("ahk_group fun")
	{ 
		Run, powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
		MsgBox, High Performance Power Profile.`n GPU Underclocked `n                  Activated
		WinWaitClose, ahk_group fun                               ; Wait for all matching windows to close
		Run, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
		MsgBox, Balance Power Profile.`n`n    GPU Normal         Activated
	}
}

#IfWinActive ahk_group last1	; Check if this group is running (High Performance Games)
; LWin::Return 			; Disables Left windows Key
!Tab::Return			; Disables Alt Tab

#IfWinActive ahk_group fun	; will do the below always
; CapsLock::Return		; Disables capslock, Not used as I use caps state always off above while this app is running.

#IfWinActive
Big thanks :D
User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

23 Nov 2021, 11:09

You should probably add Else to If WinExist("ahk_group fun") because all of the programs are in the "fun" group. That depends on what you want to happen.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

23 Nov 2021, 13:21

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

Re: Gaming Profile

24 Nov 2021, 09:11

what is the best way to add paths that will contain other programs so.
how would i do below if many of my apps are in my tool's

Code: Select all

setworkingdir %A_ScriptDir%, c:\program files (x86)\My tool's
run, NVck\nvclock.exe BaseClock+22
or just add each folder used in the setworking dir so would be better to do

Code: Select all

setworkingdir %A_ScriptDir%, c:\program files (x86)\My tool's\NVck
also found

Code: Select all

SetBatchLines, -1
Was too power hungry and removed
Also Runwait, would that wait for the above task to be completed so i may use that as its just a command
User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

24 Nov 2021, 09:37

There are various ways. I usually just include the full path in my Run line. You can include variables there if needed. If RunWait replaces Run, then the script will wait until the executed program closes.

A working directory is a single directory, not a list. You can change the Windows environment variable for Path if you like, though I usually avoid that. Another approach is to loop through selected directories to find a program of interest.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

24 Nov 2021, 11:37

will option 1 work?
Also with the runwait, were i am passing a GPU clock change i dont want the Powerprofile change to interfere in anyway
so will be running the gpu bit then waiting as it should be quick then changing power profile
Last edited by TrebleTA on 24 Nov 2021, 11:43, edited 1 time in total.
User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

24 Nov 2021, 11:42

Try it. Feel free to post a revised script if needed.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

24 Nov 2021, 11:45

Will update more tomorrow, after trying different ways thanks
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

25 Nov 2021, 06:40

Using the full path is best,
Next part is to see how to best do

Code: Select all

Run, net stop <Service-Name>
Of put them in a batch file.
User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

25 Nov 2021, 08:52

Code: Select all

If !A_IsAdmin && !RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
 Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
 ExitApp
}
svc = FoxitPhantomPDFUpdateService
F3::service(svc)        ; Start service
F4::service(svc, False) ; Stop service

service(name, start := True) {
 RunWait, % "net " (start ? "start " : "stop ") name,, Hide
}
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

25 Nov 2021, 09:20

I will look at your above scrit soon at moment am having problems with this line

Code: Select all

RunWait, C:\Program Files (x86)\My Tool's\NV Clk\NVclk.exe -setBaseClockOffset:0,0,0 -setMemoryClockOffset:0,0,0 -setPowerTarget:0,100 -setTempTarget:0,0,80
User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile  Topic is solved

25 Nov 2021, 09:47

AHK commands use commas to separate the command parameters. If you have a comma in your command line, use `,.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

25 Nov 2021, 12:47

mikeyww wrote:
25 Nov 2021, 08:52

Code: Select all

svc = FoxitPhantomPDFUpdateService 
F3::service(svc)        ; Start service
F4::service(svc, False) ; Stop service
service(name, start := True) {			
 RunWait, % "net " (start ? "start " : "stop ") name,, Hide
}
fxssvc.exe is the fax service how would i add that to your above line. trying to work out what you've typed

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 72 guests