Page 1 of 5
Gaming Profile
Posted: 20 Nov 2021, 06:55
by TrebleTA
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
Re: Gaming Profile
Posted: 20 Nov 2021, 07:03
by mikeyww
Code: Select all
Loop {
WinWait, ahk_exe notepad.exe
MsgBox, Command #1
WinWaitClose
MsgBox, Command #2
}
Re: Gaming Profile
Posted: 20 Nov 2021, 07:11
by TrebleTA
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?
Re: Gaming Profile
Posted: 20 Nov 2021, 07:30
by TrebleTA
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?
Re: Gaming Profile
Posted: 20 Nov 2021, 07:37
by mikeyww
Yes, you can make those substitutions. Use
Run to run your powercfg. I am not sure how you want to configure your text file, but
FileRead or
FileReadLine can read it.
Re: Gaming Profile
Posted: 20 Nov 2021, 07:55
by TrebleTA
@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
Re: Gaming Profile
Posted: 20 Nov 2021, 11:15
by TrebleTA
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.
Re: Gaming Profile
Posted: 20 Nov 2021, 12:52
by mikeyww
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
}
Re: Gaming Profile
Posted: 20 Nov 2021, 14:28
by TrebleTA
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?
Re: Gaming Profile
Posted: 20 Nov 2021, 14:32
by mikeyww
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
Re: Gaming Profile
Posted: 20 Nov 2021, 15:00
by TrebleTA
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
Re: Gaming Profile
Posted: 20 Nov 2021, 15:29
by mikeyww
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.
Re: Gaming Profile
Posted: 20 Nov 2021, 17:37
by TrebleTA
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
Re: Gaming Profile
Posted: 20 Nov 2021, 18:25
by mikeyww
WinWait cannot fail without a timeout. See the documentation.
Re: Gaming Profile
Posted: 21 Nov 2021, 06:16
by TrebleTA
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?
Re: Gaming Profile
Posted: 21 Nov 2021, 07:15
by mikeyww
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.
Re: Gaming Profile
Posted: 21 Nov 2021, 08:19
by TrebleTA
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
Re: Gaming Profile
Posted: 21 Nov 2021, 08:37
by mikeyww
Your ahk_exe specification looks quite strange. I do not imagine that any process name matches what you have shown. See
WinTitle and
SetTitleMatchMode.
Re: Gaming Profile
Posted: 21 Nov 2021, 08:55
by TrebleTA
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
Re: Gaming Profile
Posted: 21 Nov 2021, 09:35
by mikeyww
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:
WinTitle •
Example