High CPU USAGE ( power usage) from AHK script. This give me headache

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
alexk
Posts: 8
Joined: 16 Sep 2023, 15:36

High CPU USAGE ( power usage) from AHK script. This give me headache

05 Jan 2024, 20:39

I searched searched all forum and google.
All the people talking about power usage and cpu usage in the system not the AHK script

I have simple script with Loop with sleep in between checking what key pressed.

Now when no key is pressed and its not activated because game is not running , it should be 0.

I have cpu usage 12% and Power usage is very high.

No programs running. I need a solution.

Any expert please? Give me sample code to check a program running and if it runs , run a loop to check some key pressed.

Now if the program is not opened , cpu usage and power usage has to be zero.

Thanks much
User avatar
mikeyww
Posts: 27214
Joined: 09 Sep 2014, 18:38

Re: High CPU USAGE ( power usage) from AHK script. This give me headache

05 Jan 2024, 20:57

You can post your script on the forum to have readers examine it and provide you with specific feedback.
alexk
Posts: 8
Joined: 16 Sep 2023, 15:36

Re: High CPU USAGE ( power usage) from AHK script. This give me headache

05 Jan 2024, 21:13

Code: Select all

#HotIf WinActive("Path of Exile")

global toggle1:= false
;global Check:=0
;SetTimer  Check, 5000 

;Check:
;if (A_TimeIdlePhysical > 3000) {
;toggle1:=false
;}
;else {
;Sleep 30000
;toggle1:=true
;}

NumLock::
{
global toggle1
toggle1:= !toggle1
}


;comment  Ctrl+Alt+S - ^!s::


shiftstatus:=0
LastKey:=0

loop
{
   if 00
   sleep 5000
   
   if  WinActive("Path of Exile") 
   if  toggle1 == false
   {
   		outer:
				if GetKeyState("z","P")
				{
					send "t"
					sleep   200
					click  "down"
					sleep  100
					send "q"
					sleep   100
					send "w"
					sleep   100
					LastKey:="z"
				}
				sleep   100
	}	
	
}
https://imgur.com/a/j5vVYIK
Its simple script to not to click too many keys when you are playing hours and hurting fingers. More of one button play.

Now POE lags. So i am looking for areas to trim any other program eating resources. I saw AHK eats 12% and very high power usage when game is not running and no other programs running
Last edited by gregster on 05 Jan 2024, 21:15, edited 1 time in total.
Reason: Removed img-tags which only work with direct image links, and which broke the link above.
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: High CPU USAGE ( power usage) from AHK script. This give me headache

05 Jan 2024, 21:45

Code: Select all

   if 00
   sleep 5000
deleting the line with if 00, which makes no sense, will address the cpu usage, you are not sleeping at all since that if is always false, it's eating cpu cycles down to the nanoseconds, that's why the usage is high. As for the rest, i'm pretty sure the #HotIf takes care of the window conditional so you dont need to loop GetKeyState(z... and the extra winactive, just make a hotkey for the z key, unless it's like a "hold down" z then spam, then you could keep the loop.
alexk
Posts: 8
Joined: 16 Sep 2023, 15:36

Re: High CPU USAGE ( power usage) from AHK script. This give me headache

05 Jan 2024, 21:57

i dont like software check , i thought AHK using windows dll to get interrupt on any key pressed.
if 00 code i copied from somewhere.

i am looking for a solution. i prefer interrupt call on any key pressed.

I initially thought loop is called on interrupt.
alexk
Posts: 8
Joined: 16 Sep 2023, 15:36

Re: High CPU USAGE ( power usage) from AHK script. This give me headache

05 Jan 2024, 21:59

Can you modify the code elegantly so the functionality same. Also i want to get cpu usage when game is not running. Even if game is running i want ahk to use munimal resources as it is few lines of code.
User avatar
mikeyww
Posts: 27214
Joined: 09 Sep 2014, 18:38

Re: High CPU USAGE ( power usage) from AHK script. This give me headache

05 Jan 2024, 22:21

A general idea is below. You can run the script and then examine the Windows Task Manager to determine the resources that it uses. Rounds to zero over here, in terms of CPU.

Code: Select all

#Requires AutoHotkey v2.0
toggle1  := True
winTitle := 'Path of Exile'

#HotIf WinActive(winTitle) && toggle1
z:: {
 While GetKeyState(ThisHotkey, 'P')
  SendEvent 1
}

#HotIf WinActive(winTitle)
NumLock::Global toggle1 := !toggle1
#HotIf

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: niCode, TAC109 and 48 guests