Jump to content

High Cpu usage with MouseMove and MouseClick


Jonny22
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

In which environment do you run your script?

Hardware? Operating System? AutoIt version?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...