riflosnake / HumanCursor

Simulate Human Cursor Movement for Automated Scripts
MIT License
84 stars 15 forks source link

Library doesn't seem to work #8

Closed bedbad closed 9 months ago

bedbad commented 9 months ago

venv/lib/python3.11/site-packages/humancursor/utilities/calculate_and_randomize.py", line 72, in generate_random_curve_parameters target_points = max(int(math.sqrt((pre_origin[0] - post_destination[0]) 2 + (pre_origin[1] - post_destination[1]) 2)), 2)


TypeError: 'int' object is not subscriptable
riflosnake commented 9 months ago

Please show code you have written.

bedbad commented 9 months ago

Have this.

from humancursor import SystemCursor
import random
import time
import numpy as np
import pyautogui

cursor = SystemCursor()

# Create a display surface
screen = pygame.display.set_mode((800, 600))

running = True
while running:
    randx, randy = (random.randint(0,300), random.randint(0, 300))
    pos = pyautogui.position()
    cursor.move_to(randx+pos[0], randy+pos[1])
    time.sleep(0.1*np.linalg.norm(np.array((randx, randy))) / 100.)
bedbad commented 9 months ago

I'm looking for the performant library that does simulates mouse movements with top high performance, no latency for real-time streaming of coordinates - I'm basically taking the coordinates from a new type of pointing device

If I don't see anything else doing that I will write my own

riflosnake commented 9 months ago

You are inputting coordinates wrong, they should be in a list where first element is x coordinate, and the second is y, like this [x, y].

bedbad commented 9 months ago

That should give an error outside the library

riflosnake commented 9 months ago

Just do this cursor.move_to([randx+pos[0], randy+pos[1]]) instead of cursor.move_to(randx+pos[0], randy+pos[1]). Don't think it changes anything for you outside the library. Also make sure the numbers inside are integers, not floats.

bedbad commented 9 months ago

I got pass that, what I meant is to have input validation for API functions

On the library itself: You're using pyautogui in a loop:

    for pnt in human_curve.points:
        pyautogui.moveTo(pnt)
    pyautogui.moveTo(point)

That makes it slow, it gives it signifficant overhead as I can test it:

from humancursor import SystemCursor
import random
import time
import numpy as np
import pyautogui

import perf_timer as pft
import cv2

_cursortimer = pft.PerfTimer('cursor timer', observer=pft.HistogramObserver, quantiles=(.5,.9))

cursor = SystemCursor()

c=0
n=0
T=.0
while c !=27:
    randx, randy = (random.randint(-300,300), random.randint(-300, 300))
    pos = pyautogui.position()
    duration = np.linalg.norm(np.array((randx, randy)))/1000
    T+=duration
    with _cursortimer:
        cursor.move_to([randx+pos[0], randy+pos[1]], duration=duration)
        n+=1
    c = cv2.waitKey(10)
    print(T/n)
bedbad commented 9 months ago

timer "cursor timer": avg 2.97s ± 995ms, 50% ≤ 2.84s, 90% ≤ 4.28s in 23 runs While the durations are 0.24 s

bedbad commented 9 months ago

It might need to be reimplemented on top of better library. How does pynput look?

riflosnake commented 9 months ago

Will take a look into that, thanks for the feedback!