[PyQt] simulate fluent mouse move trajectory (Peter Irbizon)

Peter Irbizon peterirbizon at gmail.com
Wed Apr 2 12:42:12 BST 2014

Hello Lloyd,

thanks for your reply. I see I am asking wrong (mouse vs cursor, and maybe
it is not pyqt thing). I followed this code (nothing to do with pyqt) if
somebody need it too. Thanks for directing me the right way

import ctypesimport randomimport timeimport math
def move_mouse(pos):
    x_pos, y_pos = pos
    screen_size = ctypes.windll.user32.GetSystemMetrics(0),
    x = 65536L * x_pos / screen_size[0] + 1
    y = 65536L * y_pos / screen_size[1] + 1
    return ctypes.windll.user32.mouse_event(32769, x, y, 0, 0)
def random_movement(top_left_corner, bottom_right_corner,
min_speed=100, max_speed=200):
    '''speed is in pixels per second'''

    x_bound = top_left_corner[0], bottom_right_corner[0]
    y_bound = top_left_corner[1], bottom_right_corner[1]

    pos = (random.randrange(*x_bound),

    speed = min_speed + random.random()*(max_speed-min_speed)
    direction = 2*math.pi*random.random()

    def get_new_val(min_val, max_val, val, delta=0.01):
        new_val = val + random.randrange(-1,2)*(max_val-min_val)*delta
        if new_val<min_val or new_val>max_val:
            return get_new_val(min_val, max_val, val, delta)
        return new_val

    steps_per_second = 35.0
    while True:

        speed = get_new_val(min_speed, max_speed, speed)

        new_pos =

        while new_pos[0] not in xrange(*x_bound) or new_pos[1] not in
            direction  = 2*math.pi*random.random()
            new_pos =



2014-04-01 16:43 GMT+02:00 lloyd konneker <bootch at nc.rr.com>:

> You are asking to move the cursor (a viewed thing), not the mouse, which
> is a pointing device (a control.)
> Generally, in a GUI you should not move the cursor except to follow the
> mouse.  If you move the cursor in response to a mouseMoveEvent, it would be
> smooth.
> If you really want to move the cursor independently of the mouse, is your
> question about line drawing algorithms, not PyQt?
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140402/afa88a65/attachment-0001.html>

More information about the PyQt mailing list