riflosnake / HumanCursor

Simulate Human Cursor Movement for Automated Scripts
MIT License
87 stars 16 forks source link

Cursor movements vary between different devices/resolutions (?) #12

Open joostw97 opened 4 months ago

joostw97 commented 4 months ago

Hi Riflo,

Thanks for the creation of this library.

Currently I am using your library to automate some mouse movements, and I wrote all of the code on my desktop computer, but when I run the same code on my laptop, for some reason the mouse movements slow down significantly. Whereas before, for example, if the mouse took a second to travel from A to B, it would now take 1.5 seconds or so (not the actual figures).

My CPU idles at 10% load, and when running the script it might go up to 15%. I don't think it is hardware related. Do you have an idea of what it could be? Do you think it perhaps has to do with the pixels the cursor has to travel? My desktop uses 3440x1440, whereas my laptop's resolution is 1920x1080.

Many thanks for your support!

riflosnake commented 4 months ago

Hi

Thank you for using my library!

Most probably, it is the difference in resolution and screen size. I don't remember the actual implementation, but I wanted to make short movements ( 50 px vector ) inherently slower then long movements ( across the screen), as it is the natural behaviour of humans. Slow and controlled for short distances, fast and erratic for long ones.

Maybe that is why its taking longer on the smaller screen. Have you set a static duration parameter? Also higher density means more pixels, and that may affect the movement also.

joostw97 commented 4 months ago

I'll have a play around this weekend and see if I can apply some sort of measures to account for the differences in resolution/screen size.

I am using the duration; see part of my code down below:

def move_to_rapid(self, x=None, y=None):
          if x is not None and y is not None:
              random_chance = random.random()
              if random_chance < 0.01:
                  move_duration = self.rt.uni(0.1, 0.2)
              elif random_chance < 0.05:
                  move_duration = self.rt.uni(0.09, 0.15)
              elif random_chance< 0.15:
                  move_duration = self.rt.uni(0.07, 0.13)
              else:
                  move_duration = random.uniform(0.05, 0.1)

              self.cursor.move_to([x, y], duration=move_duration)
              return True

The above works well on my PC, but just really gets slowed down on my laptop. I'll report back if I manage to fix it!