首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从屏幕1移动到屏幕3,移动光标向左,反之亦然?

如何从屏幕1移动到屏幕3,移动光标向左,反之亦然?
EN

Ask Ubuntu用户
提问于 2015-11-02 09:02:00
回答 2查看 660关注 0票数 6

如果我要把鼠标从左边的屏幕一直移动到右边的屏幕,那么距离是相当大的。

有没有一种方法可以将屏幕的两侧连接起来,就像它们被安排成一个圆圈一样?然后,我可以从左边的屏幕移动到右边的屏幕,只需将光标移动到左边。

EN

回答 2

Ask Ubuntu用户

回答已采纳

发布于 2015-11-02 16:14:24

连接屏幕的

脚本“循环”

下面的脚本将按照您的描述执行;如果鼠标触及右侧(-most)屏幕的右侧边缘,鼠标将重新出现在左侧(-most)屏幕上。如果它接触到左侧屏幕的左侧,它将重新出现在右侧屏幕的右侧。

内置的预防措施

该脚本假设屏幕按x方向排列为不重叠的配置,但如果屏幕不对齐或不具有不同的y分辨率,则会进行内建校正。虽然在大多数情况下不会遇到问题,但在下面的情况下,除非脚本考虑到屏幕的y分辨率和/or (un-)对齐方面可能存在的差异,否则您会遇到这样的情况:

如果左边屏幕的顶部在右上方,光标从右上到左屏幕的顶部移动。可能是不对齐的底部同上

脚本

代码语言:javascript
复制
#!/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])])

如何使用

  1. 这个脚本需要xdotool sudo apt安装xdotool。
  2. 将脚本复制到一个空文件中,保存为circular_mouse.py
  3. 通过在终端上运行: python3 /path/ to /循环_mouse.py来测试运行脚本,您应该能够向右或向左无限移动鼠标,在屏幕上循环。
  4. 如果一切正常,将其添加到启动应用程序中:破折号>启动应用程序>添加命令: /bin/bash -c“睡眠15 & python3 /path/ to /循环_mouse.py”
票数 5
EN

Ask Ubuntu用户

发布于 2015-11-27 18:57:31

您可以尝试使用塔拉利。您需要为您自己的监视器设置编辑map_beef.c

或者,@ohayden发布了一个bash脚本这里,可以定制它来完成您想做的事情。要使用它,您需要通过运行xdotool来安装

代码语言:javascript
复制
sudo apt-get install xdotool

因为我只有一个显示器,所以我无法尝试这两种可能的解决方案。

票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/692836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档