Jump to content

WinGetTitle - reducing cpu usage

Recommended Posts


Hi Everyone,


I have been using a script at work for the last 6 months or so. It gets some information from the window title and keeps it in its memory for retrieval. 


currently I am running an infinite loop to look for the window title, the information in the memory is only updated if a few window title is detected.


The trouble with this approach as you can see, is the cpu usage. I was wondering if somehow I can only run this script when a windows change event occurs, otherwise the script stays dormant.


I have no idea how to do that, searched on forum and found some solutions that were years old and did not work for me.



Share this post

Link to post
Share on other sites


Do you have a Sleep in this infinite loop? Even a Sleep(10) gives the CPU enough time to breathe.  I have several AutoIt executables running permanently without any problems.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

@Melba23 Thanks for the golden piece of info :)

@rm65453 Can you please make a test script to demonstrate your problem :)

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)


My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!



Share this post

Link to post
Share on other sites

sorry about the late reply, did not set up email alerts for this thread.


Just tried the sleep (10) and the cpu usage is down to 1%, what a huge improvement with such a simple solution. Brilliant!!


Thanks Melba23

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • TheFixer
      By TheFixer
      Basically i am trying to make a script that detects if the currently active window is 1920 x 1080 or bigger. If it detects a window that is active, that is indeed that size. It will do some stuff. 
      The problem i am having is that it is detecting my desktop whenever i click on my desktop, so it's doing stuff when i don't want it to.

      So all i need to know, is how can i do a simple check to see if a window = a title.

      Here is what i have so far
      $wintitledesktop = WinGetTitle("[ACTIVE]") If not $wintitledesktop = "Program Manager" Then ;does stuff endif Program Manager is what my desktop is called btw. 

      The problem with that code is that the script is still detecting the desktop and doing the code.
      In case you need the whole section of the code, here it is.

      $winsizecheck1 = WinGetClientSize("[ACTIVE]") $wintitledesktop = WinGetTitle("[ACTIVE]") If WinActive("[ACTIVE]") Then sleep(100) If $winsizecheck1[0] >= 1920 Then If $winsizecheck1[1] >= 1080 Then If not $wintitledesktop = "Program Manager" Then $gamesfolderstate = WinGetState($gamesfolder) If WinExists($gamesfolder) Then If Not BitAND($gamesfolderstate, 16) Then WinSetState($gamesfolder,"",@SW_MINIMIZE) EndIf EndIf EndIf EndIf EndIf EndIf  
    • Sergeant_Shultz
      By Sergeant_Shultz
       How do I setup a Hotkey without using so much of the CPU. There must be a better way.
      HotKey Patient History.au3
    • trademaid
      By trademaid
      Im looking to measure cpu usage thats free, and measure cpu usage of a program.
      My goal is to turn intel speed step off under light cpu load.
      I think I can do that, if I can find the cpu usage.
    • UEZ
      By UEZ
      AutoIt SysInfo Clock is a small tool in widget style to show the clock, current CPU usage, CPU speed, memory usage and network activity (tcp, ip and udp). Additionally you can use it as an alarm clock. To stop alarm clock tone press the left LED (mail) or wait 60 seconds.
      The current CPU usage code is beta and might be not working for some CPUs!

      Main window:

      Move mouse to area below seconds and press rmb to select different color scheme.

      Alarm Clock window:

      Tray menu:

      Credits: see scroller (select About).
      Special thanks to trancexx for helping me to read out current CPU speed using the WinAPI stuff, AndyG for troubleshooting performance counter issue, czardas for composing "Für Elise" and Ascend4nt for the support!  
      Download source code + compiled version: Click Me (previous downloads: 1386)
      (Please don't use any download manager!)
      Compiled version only: MediaFire.com or 4Shared.com

      Coded on Win7 x64 using Aero  / Win8.1 x64 and AutoIt v3.3.12.0.
      This project is discontinued!
      Change log:
      v0.9.5.0 build 2013-06-14: initial release
      v0.9.6.0 build 2013-06-15: added _WinAPI_CreateRoundRectRgn() to fix transparency issue on non Aero desktops, small internal modifications and added check for whether performance counters are enabled
      v0.9.6.5 build 2013-06-15: fixed a bug when "Reset Windows Position" was selected twice and color of scroller will fit to clock color schema
      v0.9.8.0 build 2013-06-20: added little music to About part -> many thanks to czardas for mus++ and arranging "Für Elise", added date to clock, replaced CPU usage code -> thanks Ascend4nt
      v0.9.9.0 build 2013-06-21: added 2 more color schemas (mint and purple), added network traffic LED, compiled exe now included in archive
      v0.9.9.0 build 2013-06-22: forgot to increase a variable in ini section
      v0.9.9.0 build 2013-06-24: found also missing modification in context menue after adding two more color schemas
      v0.9.9.0 build 2013-06-26: Ops, forgot to change also radio item proper check in clock color schema sub menu
      v0.9.9.1 build 2013-06-27: added option to select whether SysInfo Clock should start at windows startup
      v0.9.9.2 build 2013-07-01: added yellow-red mark to the small info indicators and additional info when hovering about the small indicators, small internal changes
      v0.9.9.5 build 2013-07-05: added features: singleton, update check, visit web site, bring GUI to front and fixed some smaller bugs + some internal changes
      v0.9.9.6 build 2013-07-11: added alarm clock feature
      v0.9.9.7 build 2014-06-23: adapted code to run on AutoIt version
      v0.9.9.7 build 2014-08-27: some internal "cosmetic" changes -> this project is discontinued!
    • Alexxander
      By Alexxander
      Hi all
      this is a part from my script
      #include <Misc.au3> $dll = DllOpen("user32.dll") While 1 If _IsPressed("31", $dll) Then one() If _IsPressed("32", $dll) Then two() WEnd Func one() MsgBox(0, "", "1") While _IsPressed("31") or _IsPressed("61") Sleep(1) WEnd EndFunc Func two() MsgBox(0,"", "2") While _IsPressed("32") or _IsPressed("62") Sleep(1) WEnd EndFunc it is working fine but it takes 30 % of the CPU usage and it is a small simple script
      when i put sleep(100) in the while loop the CPU is 1%
      i think that this is a good solution but not for my case cuz the rest of my script really depends on time and 100 msec will matter
      can i reduce the CPU usage without using sleep ?

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.