Gaming Profile Topic is solved

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

Gaming Profile

20 Nov 2021, 06:55

Hi all, and a big thank you for AHK.

I think I'll ask here, as sure your sort it in minutes but I after a AHK so it will detect a game, and then will run commands, say if that game is running it will change power profile, or other commands. But then detects the game has close and then revert changes.

Thank in advance
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

20 Nov 2021, 07:03

Code: Select all

Loop {
 WinWait, ahk_exe notepad.exe
 MsgBox, Command #1
 WinWaitClose
 MsgBox, Command #2
}
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

20 Nov 2021, 07:11

So say the game exe is world of warcraft so wow.exe then will swap power profile so be powercfg -setactive etc

So notepad.exe = wow.exe
Command #1 = powercfg -setactive
Is that right?
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

20 Nov 2021, 07:30

Also say I wanted ahk to read a file that has a list of game exe in it with say a command so be like wow.exe1, anno.exe, etc
The 1 would point to a different command?
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

20 Nov 2021, 07:37

Yes, you can make those substitutions. Use :arrow: Run to run your powercfg. I am not sure how you want to configure your text file, but :arrow: FileRead or FileReadLine can read it.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

20 Nov 2021, 07:55

@mikeyww thanks for the help.

I'm not at home at the moment will be in a hour or 2, my miss had got me out and about.
So will start trying to get this working then. But how would you think it is best?

To get me started

Thanks again
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

20 Nov 2021, 11:15

ok i have this so far

Code: Select all

Loop {
 #SingleInstance ignore
 WinWait, ahk_exe notepad.exe
 if ErrorLevel
  {
    MsgBox, WinWait timed out.
    return
  }
 else
  MsgBox, test high
  Run, C:\Windows\System32\powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
  ;Disable Alt+Tab
  !Tab::Return
  WinWaitClose
  MsgBox, test Bal
 Run, C:\Windows\System32\powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
}
But its not detecting that notepad is now closed.
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

20 Nov 2021, 12:52

Get the basics working first. After it works, you can expand. See whether the following works.

Code: Select all

#SingleInstance Force
Loop {
 WinWait, ahk_exe notepad.exe
 Run, powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
 WinWaitClose
 Run, powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
}
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

20 Nov 2021, 14:28

HI and thanks.

Code: Select all

#SingleInstance Force
Loop {
 WinWait, ahk_exe notepad.exe
 MsgBox, Hi Active
  if ErrorLevel {
    MsgBox, WinWait timed out.
    return
  }
 else
 Run, Powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
 WinWaitClose
 MsgBox, Balance Active
 Run, Powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
}
Works soon as I added my disable alt tab it fails. well the alt tab is disabled just the winwaitclose is not noticed. could put the alt tab in to a exe then call that?

Code: Select all

; Disable Alt+Tab
!Tab::Return
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

20 Nov 2021, 14:32

Code: Select all

Loop {
 WinWait, % winTitle := "ahk_exe notepad.exe"
 SoundBeep, 1500
 Run, Powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
 WinWaitClose
 SoundBeep, 1000
 Run, Powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
}
#If WinExist(winTitle)
!Tab::Return
#If
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

20 Nov 2021, 15:00

Hi and thanks this is what I have so far

Code: Select all

#SingleInstance Force
Loop 
{
 WinWait, % winTitle := "ahk_exe notepad.exe"
 MsgBox, Hi Active
  if ErrorLevel 
  {
    MsgBox, WinWait timed out.
    return
  }
 else
 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
}
#If WinExist(winTitle)
; Disable Alt+Tab
!Tab::Return				
; Disable Left Windows Key
LWin::Return
; CapsLock 
CapsLock::Return
SetCapsLockState, Off
#If
I Sorted the SetCapsLockState, Am out of time now but tomorrow will start at looking at loading files from a text file.

Thank you so much for the help
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

20 Nov 2021, 15:29

Without a timeout on WinWait, the command will wait indefinitely and will then succeed with ErrorLevel = 0. That is probably the desired effect here.

#If is only for hotkeys and hotstrings. SetCapsLockState, Off will never execute, because it follows Return.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

20 Nov 2021, 17:37

Apon starting ahk its setting caps lock off then it's not read, just capslock return.
Also the winwait error check was if it failed would warn
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

20 Nov 2021, 18:25

WinWait cannot fail without a timeout. See the documentation.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 06:16

Morning.
So the error check is pointless, As I dont want it to time out. Can be gaming for 12hrs if I get lucky.
For the capslock as you say the state is not checked how would I go sorting that, put the state at the start?
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 07:15

Yes, the error check serves no role, because an error will not occur.
Timeout: How many seconds to wait before timing out and setting ErrorLevel to 1. Leave blank to allow the command to wait indefinitely. ErrorLevel is set to 1 if the command timed out or 0 otherwise.
You can move "running code" such as your CapsLock check to the top of the script, in the auto-execute section.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 08:19

Hi thanks this is what i have now

Code: Select all

#SingleInstance Force

FileRead, OutputVar, game.txt
if ErrorLevel  ;If a Error
{
    MsgBox, File not found.
}
else
 Loop 
 {
  WinWait, % winTitle := "ahk_exe OutputVar=*.*"
  MsgBox, Hi Active
  Run, C:\Windows\System32\Powercfg.exe /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
  SetCapsLockState, Off
  WinWaitClose
  MsgBox, Balance Active
  Run, C:\Windows\System32\Powercfg.exe /setactive 381b4222-f694-41f0-9685-ff5bb260df2e
 }
 #If WinExist(winTitle)
 ; Disable Alt+Tab
 !Tab::Return				
 ; Disable Left Windows Key
 LWin::Return
 ; CapsLock 
 CapsLock::Return
#If
My problem now is reading the file to then enter to the winwait, In the game.txt at moment i just have notepad.exe
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 08:37

Your ahk_exe specification looks quite strange. I do not imagine that any process name matches what you have shown. See WinTitle and SetTitleMatchMode.
TrebleTA
Posts: 134
Joined: 20 Nov 2021, 06:44

Re: Gaming Profile

21 Nov 2021, 08:55

Not quite sure how you mean, For testing am using notepad.txt but it will be a list of games in the games.txt.
So am looking to load the game.txt in to memory check to see if x game is running then do the Power profile changing, then will be changing GPU settings, and disabling keys. then once the game is close autohotkey will close.
Thanks for the help
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Gaming Profile

21 Nov 2021, 09:35

On line 11, you have written WinWait, % winTitle := "ahk_exe OutputVar=*.*", but that does not look like a process name, so I imagine that you will have an infinite wait at that point. You can test your script and see whether that is the case. As far as I know, all valid process names end in .exe.

Explained: WinTitleExample

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 43 guests