如果我要把鼠标从左边的屏幕一直移动到右边的屏幕,那么距离是相当大的。
有没有一种方法可以将屏幕的两侧连接起来,就像它们被安排成一个圆圈一样?然后,我可以从左边的屏幕移动到右边的屏幕,只需将光标移动到左边。
发布于 2015-11-02 16:14:24
连接屏幕的
下面的脚本将按照您的描述执行;如果鼠标触及右侧(-most)屏幕的右侧边缘,鼠标将重新出现在左侧(-most)屏幕上。如果它接触到左侧屏幕的左侧,它将重新出现在右侧屏幕的右侧。
该脚本假设屏幕按x方向排列为不重叠的配置,但如果屏幕不对齐或不具有不同的y分辨率,则会进行内建校正。虽然在大多数情况下不会遇到问题,但在下面的情况下,除非脚本考虑到屏幕的y分辨率和/or (un-)对齐方面可能存在的差异,否则您会遇到这样的情况:

如果左边屏幕的顶部在右上方,光标从右上到左屏幕的顶部移动。可能是不对齐的底部同上
#!/usr/bin/env python3
import subprocess
import time
def get_screendata():
data = [s.split("+") for s in subprocess.check_output(["xrandr"]).decode("utf-8").split() \
if s.count("+") == 2]
# calculate total x-size of spanning screens
x_span = sum([int(item[0].split("x")[0]) for item in data])
# sort screens to find first/last screen (also for 2+ screens)
data.sort(key=lambda x: x[1])
# find (possible) screen offset of first/last screen and vertical area
scr_first = data[0]; shiftl = int(scr_first[2])
areal = [shiftl, shiftl+int(scr_first[0].split("x")[1])]
scr_last = data[-1]; shiftr = int(scr_last[2])
arear = [shiftr, shiftr+int(scr_last[0].split("x")[1])]
return (x_span, areal, arear)
screendata = get_screendata()
x_span = screendata[0]; areal = screendata[1]; arear = screendata[2]
new_coords = []
while True:
time.sleep(0.5)
new_coords = []
# read the current mouse position
pos = [int(s.split(":")[-1]) for s in \
subprocess.check_output(["xdotool", "getmouselocation"]).decode("utf-8").split()\
if any(["x" in s, "y" in s])]
# if the mouse is on the left of the first screen
if pos[0] == 0:
new_coords.append(x_span-2)
if pos[1] <= arear[0]:
new_coords.append(arear[0]+2)
elif pos[1] >= arear[1]:
new_coords.append(arear[1]-2)
else:
new_coords.append(pos[1])
# if the mouse is on the right of the last screen
elif pos[0] > x_span-2:
new_coords.append(2)
if pos[1] <= areal[0]:
new_coords.append(areal[0]+2)
elif pos[1] >= areal[1]:
new_coords.append(areal[1]-2)
else:
new_coords.append(pos[1])
# move the mouse
if new_coords:
subprocess.Popen(["xdotool", "mousemove", str(new_coords[0]), str(new_coords[1])])xdotool sudo apt安装xdotool。circular_mouse.pyhttps://askubuntu.com/questions/692836
复制相似问题