Jump to content
Sign in to follow this  
Jonny22

High Cpu usage with MouseMove and MouseClick

Recommended Posts

Jonny22

Hi

I have a porblem with mouse move and click. If i leave the speed default or change it higher than 1, it use my cpu more 30%. Anybody know why I have this problem? What can I do to fix this ?

The simple code :

$counter = 0
while $counter < 20
MouseMove(Random(800,1700,1),Random(400,900,1))
Sleep(200)
MouseClick("left")
$counter = $counter + 1
WEnd

thanks

Share this post


Link to post
Share on other sites
FireFox

Hi,

Welcome to the AutoIt forum :)

You need to do a sleep in the thread :

$counter = 0
while $counter < 20
MouseMove(Random(800,1700,1),Random(400,900,1))
Sleep(200)
MouseClick("left")
$counter = $counter + 1
Sleep(100)
WEnd

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
water

Modify MouseMove to make the move instantly.

MouseMove(Random(800,1700,1),Random(400,900,1), 0)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jonny22

I have made an other sleep but it's no help. And about change move instantly it's no good for me because it's like jump not move...

Share this post


Link to post
Share on other sites
water

Try both and you'll see that the instant move doesn't use much CPU. So you have to decide: High CPU usage or "mouse jump".

Out of curiosity: What do you need this for?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Just wanted to have a script without Random to get reproducable results.

$counter = 0
While $counter < 20
    If Mod($counter, 2) = 0 Then
        $i = MouseMove(10, 10)
     Else
        $i = MouseMove(700, 700)
     EndIf
     Sleep(200)
    ;MouseClick("left")
     $counter = $counter + 1
WEnd
Surprisingly I now can't reproduce the high CPU consumption. My bad, parameter 3 of MouseMove was set to 1 (fast movement).

I'm running Windows 7 64 bit on a VM machine.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jonny22

I know instant move is using less CPU but I need to slow it down. I thought there is an other way , because I have got a C++ application from my friend and it does this job with low Cpu usage.

Share this post


Link to post
Share on other sites
BrewManNH

I ran the script from the first post and my CPU usage never went above 0-1%, and this is on my nearly 5 year old Win7 PC.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Jonny22

It is strange because I have sent my script to my friend to test and he had also high CPU usage.

I have windows 7 64bit Intel dual core e6700 3,2 Ghz processor.

Share this post


Link to post
Share on other sites
water

In which environment do you run your script?

Hardware? Operating System? AutoIt version?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
ileandros

Try compiling the script and then run it.

If its just mouseclicks or moves then its propably ur pc or the way you have written ur script.

I think your script is not the 5 lines you have above... If you CALL mousemovements or click from an other function and you DON'T call them right they will take a lot of cpu usage and even crash the script after some time.


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
water

The reproducer the OP posted gives me the high CPU too. The high CPU consumption is related to the MouseMove function.

For $counter = 1 To 20
    If Mod($counter, 2) = 0 Then
        MouseMove(10, 10)
    Else
        MouseMove(700, 700)
    EndIf
    Sleep(200)
Next
This gives me high CPU usage running compiled or from SciTe as 32 or 64 bit with AutoIt 3.3.81 or 3.3.9.4 from my Windows 7 in a VirtualBox machine. Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jonny22

I am back again and my problem still have. I have tried autohotkey work fine and I load autoit functions to C++ and that also work well.

I have installed older version of autoit also (3.3.8.0) but the problem is same, to much cpu usage. Have any other idea what causes it?

my autoit code:

$counter = 0
while $counter < 5
    MouseMove(200,200,30)
        Sleep(200)
    MouseMove(600,700,30)
        Sleep(200)
    
    $counter = $counter + 1
        Sleep(100)
WEnd

My conf: windows 7 64bit Intel dual core e6700 3,2 Ghz processor, 4gb 1066 mhz memory.

Share this post


Link to post
Share on other sites
BrewManNH

I ran the latest script posted on my Win7 machine, and I was seeing the same issue. I didn't see the issue previously because I had another process running that was taking up all the CPU when it's idle (boinc) so it didn't show up at first.

It only happens when you use a delay though, and I know you stated you didn't want to use the instant move, but if it only happens when you're using MouseMove, and it stops as soon as the script idles, what's the issue?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
water

I just tried it on my Windows 7 machine. I get the high CPU consumption as well.

I can imagine why:

If you set parameter "speed" to 0 the mouse is moved instantly and only a single operation is executed (show the mouse at the new coordinates).

If you set parameter "speed" to > 0 then a lot of trigonometric calculations have to be done to show the mouse at any location between source and target location. This soaks up the CPU.

My summary: If you want to see the mouse move to the target location you have to live with the high CPU consumption!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×