Sign in to follow this  
Followers 0
Jabberwock

high cpu usage?

9 posts in this topic

Anyone want to try and explain why such a simple program is using soo much cpu load while running in the background? seems to do it with any hotkey.

HotKeySet("{F11}", "hello") 

While 1 
Wend
Func hello()
Send("Hello")
Send("{Enter}")
EndFunc

Share this post


Link to post
Share on other sites



Anyone want to try and explain why such a simple program is using soo much cpu load while running in the background? seems to do it with any hotkey.

HotKeySet("{F11}", "hello") 

While 1 
Wend
Func hello()
Send("Hello")
Send("{Enter}")
EndFunc
You need to add a sleep in your script, if all your doing is hotkeys you could do:
HotKeySet("{F11}", "hello") 

While 1
    Sleep(1000000)
Wend

Func hello()
    Send("Hello {ENTER}")
EndFunc

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Or if you want to use things inside your loop as well you could just put a GuiGetMsg() in it, instead of a sleep.

Alzo


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Or if you want to use things inside your loop as well you could just put a GuiGetMsg() in it, instead of a sleep.

Alzo

That's a good point marf, I wonder if there is a default delay for GuiGetMsg() like there is for AdlibEnable().

Edit:

The test I did looks like 10 milleseconds... but I'm not sure if that was programmed that way. (I'm sure it was)

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I always (most of the time :D ) do a

While 1
   $msg = GetGuiMsg()
   ; select switch or if
   if $msg = 0 then sleep(250) ; or as long as I dare, nothing to do anyway
WEnd

But as @SmoKe_N pointed out you don't need the GuiGetMsg when only using hotkeys.

Edited by Uten

Share this post


Link to post
Share on other sites

and it's useless if using GUIOnEventMode. :D


Share this post


Link to post
Share on other sites

and it's useless if using GUIOnEventMode. :D

That depends on 2 things, if 1, you actually have a reason for using Opt('GUIOnEventMode', 1) (like using a GUI) and 2, if you don't mind a Sleep(250) in Uten's example every time (which I agree is a waiste in that aspect), becuase with Opt('GUIOnEventMode', 1), then GUIGetMsg() returns 0 every time (thus the Sleep(250)).

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Either way you need the loop and this script sample will probably grove. So why not learn "good" habits? Sleep as long as you dare (to off load your system) but not to much either because you will miss something important.

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
Sign in to follow this  
Followers 0