自动将鼠标移动到焦点窗口

Kad*_*dir 5 mouse focus

是否可以将鼠标自动移动到通过按键获得焦点的窗口中的任何位置?

例如:

  1. 有两个监视器。
  2. 鼠标位于左侧显示器的左边缘附近。
  3. 使用Alt+Tab切换位于右侧监视器的窗口,您必须将鼠标移动到该窗口。
  4. 自动或至少使用键盘快捷键将鼠标移入此窗口会很棒。

dec*_*yte 1

我只是有同样的需求,最终来到这里寻找问题的解决方案。

由于这看起来不像其他人在其他地方解决过的问题,因此我使用基本的 shell 技能创建了以下脚本,该脚本使用以下命令完成这项工作xdotool

# Get geometry information of the currently active window.
GEOMETRY=`xdotool getwindowgeometry $(xdotool getactivewindow)`                 
# Extract information about the dimensions of the window and divide
# both of them by 2.
DIMENSIONS=$(echo "$GEOMETRY" | grep -Po "[0-9]+x[0-9]+")                       
X=$(echo $DIMENSIONS | sed 's/x[0-9]\+//g')                                     
Y=$(echo $DIMENSIONS | sed 's/[0-9]\+x//g')                                     
X=$(expr $X / 2)                                                                
Y=$(expr $Y / 2)                                                                
# Move the mouse cursor to the middle of the active window.
xdotool mousemove -w $(xdotool getactivewindow) $X $Y
Run Code Online (Sandbox Code Playgroud)

我已将其放入文件中,并添加了运行它的自定义键盘快捷键。