Change power plan when window active

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Tom1
Posts: 24
Joined: 17 Sep 2018, 12:05
Contact:

Change power plan when window active

06 Apr 2019, 03:21

Hello,

I'd like AutoHotkey to change the active power plan to "High Performance" when a specific window is active, and if not, change to "Balanced".

I've tried #IfWinActive, it didn't work, then I realized it's only for manual Hotkeys, that you have to press. Then I've tried IfWinActive, but nothing happens.

Code: Select all

if WinExist("ahk_class Overwatch")
run, powercfg /s 6bfea957-e2a2-4156-b4f2-dae9c536302c
return
I would like the first command to run when a specific window is active, and the 2nd one to run when it is not active.

Code: Select all

run, powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e ;Balanced Power plan
run, powercfg /s 6bfea957-e2a2-4156-b4f2-dae9c536302c ;High Perfomance Power plan
Can someone help me out? I appreciate any help
User avatar
Tom1
Posts: 24
Joined: 17 Sep 2018, 12:05
Contact:

Change power plan when window active

10 Apr 2019, 07:46

I figured out how to make the code working, but it closes immediately after run.

Code: Select all

if WinActive("Overwatch")
{
	run, powercfg /s 6bfea957-e2a2-4156-b4f2-dae9c536302c
	return
}
else
{
	run, powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e
	return
}
return
It closes itself, because it doesn't know that I want it to keep looking for window changes, and if changes occur, that it should run the appropriate command...It'll prob take me a lot more google searches and looking through autohotkey help site, since I've no idea what the hell to search for, to find my solution.
Portwolf
Posts: 155
Joined: 08 Oct 2018, 12:57

Re: Change power plan when window active

10 Apr 2019, 08:52

Put that inside a timer?
(not tested)

Code: Select all

SetTimer, overpower, 1000

overpower:
	if WinActive("Overwatch")
	{
		run, powercfg /s 6bfea957-e2a2-4156-b4f2-dae9c536302c
	}
	else
	{
		run, powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e
	}
return
gregster
Posts: 2808
Joined: 30 Sep 2013, 06:48

Re: Change power plan when window active

10 Apr 2019, 09:05

And note this:
https://autohotkey.com/docs/commands/SetTimer.htm#Remarks wrote:To keep a script running -- such as one that contains only timers -- use #Persistent.
User avatar
Tom1
Posts: 24
Joined: 17 Sep 2018, 12:05
Contact:

Re: Change power plan when window active

10 Apr 2019, 09:39

Thank you for the replies. Is there no way to only run the commands, when the window state changes? (from inactive to active & vice versa)

With the 1 sec timer, the command prompt keeps popping up every sec. I really only want the commands to send, when the window state changes.

Thanks again..
Nighty
Posts: 1
Joined: 20 Jun 2019, 21:51

Re: Change power plan when window active

21 Jun 2019, 00:21

Hi, this should work. (I've not tested it with Overwatch.)

Code: Select all

; Automatic Power Plan Switcher
; v1.0 2019-06-21

#NoEnv
#Warn
#SingleInstance, force
#Persistent

; a1841308-3541-4fab-bc81-f71556f20b4a  Power Saver
; 381b4222-f694-41f0-9685-ff5bb260df2e  Balanced
; 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c  High Performance

; Track High Performance plan status
IsHighPerf := False

; Set tray icon
Menu, Tray, Icon, Shell32.dll, 77

SetTimer, AutoPPS, 3000
return

AutoPPS:
if WinExist("Overwatch") or WinExist("Heroes of the Storm") or WinExist("Path of Exile") {
    ; Change to High Performance power plan if not already set
    if ( IsHighPerf = False ) {
        Run, powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c, , Hide
        IsHighPerf := True
    }
}
else {
    ; Change to Balanced power plan if not already set
    if ( IsHighPerf = True ) {
        Run, powercfg /s 381b4222-f694-41f0-9685-ff5bb260df2e, , Hide
        IsHighPerf := False
    }
}
return


Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Getfree, JoeWinograd and 150 guests