I want to know when an application is busy by a popup Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newbeeb3
Posts: 8
Joined: 04 Apr 2020, 17:37

I want to know when an application is busy by a popup

04 Apr 2020, 17:43

Hi,

There is an application that may be working and thinking (with no indication) or otherwise it is just idling. (For information it has the name of the application in the title and if I open the task manager I can see there are often several processes that belong to it.) This is Windows 10.

If the application is busy/working it is bad to click in it further as this just queues requests to be handled once its done with whatever it's doing. But I'm just learning this application so I don't know if it's busy or not.

What I would like is for a small draggable popup rectangle to pop up any time the CPU utilization of the software in question is above 1% and disappear once it falls below 1%. This should be present anywhere on my screen so that I can go do my work in another program and just notice when the red popup has disappeared.

If you do it by polling, the polling frequency should be about 1 per second. (I would wait at least a second after interacting with the application).

I hope you can help me do this. I don't need any other functionality. Thank you.
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: I want to know when an application is busy by a popup

05 Apr 2020, 06:33

https://www.autohotkey.com/boards/viewtopic.php?p=311412#p311412 + Process (to get the correct PID) should do the trick :)

Code: Select all

#Persistent
PID := 9688 ; specify Process ID

timer := Func("GetProcessCpu").Bind(PID)
GetProcessCpu(PID)
SetTimer, % timer, 1000
Return

GetProcessCpu(PID) {
   static time, coreNumber, prevProcTime, prevTickCount
   if !coreNumber {
      VarSetCapacity(time, 32)
      VarSetCapacity(SYSTEM_INFO, 24 + A_PtrSize*3)
      DllCall("GetSystemInfo", "Ptr", &SYSTEM_INFO)
      coreNumber := NumGet(SYSTEM_INFO, 8 + A_PtrSize*3, "UInt")
   }
   GetProcessTime(PID, time)
   kernelTime := NumGet(time, 16, "UInt64") / 10000
   userTime   := NumGet(time, 24, "UInt64") / 10000
   procTime := kernelTime + userTime
   if prevProcTime
      cpu := Round((procTime - prevProcTime)/coreNumber/(A_TickCount - prevTickCount) * 100, 2)
   prevProcTime := procTime
   prevTickCount := A_TickCount
   ToolTip % cpu
}

GetProcessTime(PID, ByRef time) {
   hProc := DllCall("OpenProcess", "UInt", PROCESS_QUERY_INFORMATION := 0x400, "UInt", false, "UInt", PID, "Ptr")
   DllCall("GetProcessTimes", "Ptr", hProc, "Ptr", &time, "Ptr", &time + 8, "Ptr", &time + 16, "Ptr", &time + 24)
   DllCall("CloseHandle", "Ptr", hProc)
}
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
newbeeb3
Posts: 8
Joined: 04 Apr 2020, 17:37

Re: I want to know when an application is busy by a popup

05 Apr 2020, 15:00

BNOLI wrote:
05 Apr 2020, 06:33
https://www.autohotkey.com/boards/viewtopic.php?p=311412#p311412 + Process (to get the correct PID) should do the trick :)

Code: Select all

#Persistent
PID := 9688 ; specify Process ID

timer := Func("GetProcessCpu").Bind(PID)
GetProcessCpu(PID)
SetTimer, % timer, 1000
Return

GetProcessCpu(PID) {
   static time, coreNumber, prevProcTime, prevTickCount
   if !coreNumber {
      VarSetCapacity(time, 32)
      VarSetCapacity(SYSTEM_INFO, 24 + A_PtrSize*3)
      DllCall("GetSystemInfo", "Ptr", &SYSTEM_INFO)
      coreNumber := NumGet(SYSTEM_INFO, 8 + A_PtrSize*3, "UInt")
   }
   GetProcessTime(PID, time)
   kernelTime := NumGet(time, 16, "UInt64") / 10000
   userTime   := NumGet(time, 24, "UInt64") / 10000
   procTime := kernelTime + userTime
   if prevProcTime
      cpu := Round((procTime - prevProcTime)/coreNumber/(A_TickCount - prevTickCount) * 100, 2)
   prevProcTime := procTime
   prevTickCount := A_TickCount
   ToolTip % cpu
}

GetProcessTime(PID, ByRef time) {
   hProc := DllCall("OpenProcess", "UInt", PROCESS_QUERY_INFORMATION := 0x400, "UInt", false, "UInt", PID, "Ptr")
   DllCall("GetProcessTimes", "Ptr", hProc, "Ptr", &time, "Ptr", &time + 8, "Ptr", &time + 16, "Ptr", &time + 24)
   DllCall("CloseHandle", "Ptr", hProc)
}

Thanks. I can clearly see it is advanced enough to use but I am not advanced enough to use it.

The process trick means I can launch the application myself and know the process ID, like the example

Run notepad.exe,,, NewPID
Process, Priority, %NewPID%, High
MsgBox The newly launched Notepad's PID is %NewPID%.

I am able to change this from "notepad.exe" to the name of the application I want.

As for the rest of the code, could you put it together for me so it behaves as I mentioned? (After the first three lines). I don't know autohotkey well enough, this is why I'm asking for help. I'll let you know if it works. Thanks!
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: I want to know when an application is busy by a popup  Topic is solved

05 Apr 2020, 15:31

Spoiler
:?: :silent:
Last edited by BNOLI on 05 Apr 2020, 15:33, edited 1 time in total.
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
newbeeb3
Posts: 8
Joined: 04 Apr 2020, 17:37

Re: I want to know when an application is busy by a popup

05 Apr 2020, 17:07

:?: :silent:

Thanks so much! yes this does what I wanted. (and thanks for the comments you left in the code.) I'm using it right now. if there is change I can't do myself I'll reply again. Thanks again.
newbeeb3
Posts: 8
Joined: 04 Apr 2020, 17:37

Re: I want to know when an application is busy by a popup

05 Apr 2020, 17:19

BNOLI wrote:
05 Apr 2020, 15:31
:?: :silent:
Actually I do have a request. There are normal natural tooltips in the program and they interfere with these tooltips. I couldn't figure out how to move the location. Can you show me how to change the tooltip line so that it's at -10, -10 relative to the mouse? (down and to the left? I tried to do it following the documentation for "tooltip" but didn't succeed.
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: I want to know when an application is busy by a popup

06 Apr 2020, 07:20

So you have to identify the current mouse position (MouseGetPos) within the function (right before the new ToolTip will get created) and do some math on its detected coordinates. Done that, use the now edited/manipulated coordinates with the next ToolTip.
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, Chunjee, macromint, peter_ahk and 325 guests