Quantcast
Viewing latest article 9
Browse Latest Browse All 31

Moving mouse pointer in X using xpyb.

xcb_pointer_control.py
#!/usr/bin/env python
# requires xpyb - XCB bindings for python
import xcb
import xcb.xproto
from time import sleep
from itertools import tee
from functools import partial
conn = xcb.connect()
screen = conn.get_setup().roots[0]
window = screen.root
def draw_with_pointer(speed, xs, ys):
period = 1.0/speed
for x, y in zip(xs, ys):
conn.core.WarpPointerChecked(0, window, 0, 0, 0, 0, x, y).check()
sleep(period)
def diagonal(width, height, xs):
y = lambda x: x * float(height) / width
xs1, xs2 = tee(xs)
return xs1, map(y, xs2)
def circle_left_right(r, x0, xs):
import math
def y(x):
x_circle = x - x0
if abs(x_circle) > r:
return r
elif x % 2 == 0:
return r + math.sqrt(pow(r, 2) - pow(x_circle, 2))
else:
return r - math.sqrt(pow(r, 2) - pow(x_circle, 2))
xs1, xs2 = tee(xs)
return xs1, map(y, xs2)
def sin(scale_x, scale_y, xs):
import math
def y(x):
return scale_y - scale_y * math.sin(2 * math.pi * float(x) / scale_x)
xs1, xs2 = tee(xs)
return xs1, map(y, xs2)
def circle(r, x0, y0, rounds, xs):
import math
xs = list(xs)
xs = map(lambda x: float(x) / len(xs) * rounds, xs)
xs, ys = tee(map(lambda x: 2 * math.pi * x, xs))
xs = map(math.sin, xs)
xs = map(lambda x: x0 + x * r, xs)
ys = map(math.cos, ys)
ys = map(lambda y: y0 + y * r, ys)
return xs, ys
width = screen.width_in_pixels
height = screen.height_in_pixels
diagonal = partial(diagonal, width, height)
circle_left_right = partial(circle_left_right, height / 2, width / 2)
sin = partial(sin, width, height / 2)
circle = partial(circle, height / 2, width / 2, height / 2, 5)
draw_with_pointer(1000, *diagonal(range(width)))
draw_with_pointer(1000, *circle_left_right(range(width)))
draw_with_pointer(1000, *sin(range(width)))
draw_with_pointer(1000, *circle(range(width)))

Viewing latest article 9
Browse Latest Browse All 31

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>