原理:基于xdotool命令
xdotool命令可以让你获取鼠标在屏幕上的位置,并且让你能够控制你的鼠标移动!!!
xdotool命令安装:
sudo apt install xdotool
画圆算法:分为四个象限,对每个象限进行不同的处理
shell脚本代码如下:
1、以当前鼠标的停放位置为起点。
2、目前默认从圆的最左边开始画。
3、通过修改下方RADIUS变量的值来修改圆的半径。
#!/bin/bash
RADIUS=200
cur_x=`xdotool getmouselocation | cut -d ' ' -f 1 | cut -d ':' -f 2`
cur_y=`xdotool getmouselocation | cut -d ' ' -f 2 | cut -d ':' -f 2`
circle_x=`echo "$cur_x+$RADIUS" | bc -l`
circle_y=$cur_y
echo "1quadrant"
for ((i = 0; i <= 90; i += 5)); do
tmp=`echo "scale=10;$i*3.1415926/180" | bc`
new_x=`echo "scale=10;$RADIUS*c($tmp)+0.5" | bc -l`
new_y=`echo "scale=10;$RADIUS*s($tmp)+0.5" | bc -l`
new_x=${new_x%%.*}
new_y=${new_y%%.*}
if [[ $new_x -lt 1 ]]
then
new_x=0
fi
if [[ $new_y -lt 1 ]]
then
new_y=0
fi
new_x=${new_x%%.*}
new_y=${new_y%%.*}
new_x=`echo "$circle_x-$new_x" | bc -l`
new_y=`echo "$circle_y-$new_y" | bc -l`
new_x_offset=`echo "$new_x-$cur_x" | bc -l`
new_y_offset=`echo "$new_y-$cur_y" | bc -l`
xdotool mousemove_relative -- $new_x_offset $new_y_offset
sleep 0.001
cur_x=`xdotool getmouselocation | cut -d ' ' -f 1 | cut -d ':' -f 2`
cur_y=`xdotool getmouselocation | cut -d ' ' -f 2 | cut -d ':' -f 2`
done
echo "2quadrant"
cur_x=`xdotool getmouselocation | cut -d ' ' -f 1 | cut -d ':' -f 2`
cur_y=`xdotool getmouselocation | cut -d ' ' -f 2 | cut -d ':' -f 2`
circle_x=$cur_x
circle_y=`echo "$cur_y+$RADIUS" | bc -l`
for ((i = 90; i <=180; i += 5)); do
tmp=`echo "scale=10;$i*3.1415926/180" | bc`
new_x=`echo "scale=10;$RADIUS*c($tmp)+0.5" | bc -l`
new_y=`echo "scale=10;$RADIUS*s($tmp)+0.5" | bc -l`
new_x=${new_x%%.*}
new_y=${new_y%%.*}
if [ -z $new_x ];
then
if [[ $new_x -lt 1 ]]
then
new_x=0
fi
fi
if [[ $new_y -lt 1 ]]
then
new_y=0
fi
new_x=${new_x%%.*}
new_y=${new_y%%.*}
new_x=`echo $(($new_x*-1))`
new_x=`echo "$circle_x+$new_x" | bc -l`
new_y=`echo "$circle_y-$new_y" | bc -l`
new_x_offset=`echo "$new_x-$cur_x" | bc -l`
new_y_offset=`echo "$new_y-$cur_y" | bc -l`
xdotool mousemove_relative -- $new_x_offset $new_y_offset
sleep 0.001
cur_x=`xdotool getmouselocation | cut -d ' ' -f 1 | cut -d ':' -f 2`
cur_y=`xdotool getmouselocation | cut -d ' ' -f 2 | cut -d ':' -f 2`
done
echo "3quadrant"
cur_x=`xdotool getmouselocation | cut -d ' ' -f 1 | cut -d ':' -f 2`
cur_y=`xdotool getmouselocation | cut -d ' ' -f 2 | cut -d ':' -f 2`
circle_x=`echo "$cur_x-$RADIUS" | bc -l`
circle_y=$cur_y
for ((i = 180; i <=270; i += 5)); do
tmp=`echo "scale=10;$i*3.1415926/180" | bc`
new_x=`echo "scale=10;$RADIUS*c($tmp)+0.5" | bc -l`
new_y=`echo "scale=10;$RADIUS*s($tmp)+0.5" | bc -l`
new_x=${new_x%%.*}
new_y=${new_y%%.*}
if [ -z $new_x ];
then
if [[ $new_x -lt 1 ]]
then
new_x=0
fi
fi
if [ -z $new_y ];
then
if [[ $new_y -lt 1 ]]
then
new_y=0
fi
fi
new_x=${new_x%%.*}
new_y=${new_y%%.*}
new_x=`echo $(($new_x*-1))`
new_y=`echo $(($new_y*-1))`
new_x=`echo "$circle_x+$new_x" | bc -l`
new_y=`echo "$circle_y+$new_y" | bc -l`
new_x_offset=`echo "$new_x-$cur_x" | bc -l`
new_y_offset=`echo "$new_y-$cur_y" | bc -l`
xdotool mousemove_relative -- $new_x_offset $new_y_offset
sleep 0.001
cur_x=`xdotool getmouselocation | cut -d ' ' -f 1 | cut -d ':' -f 2`
cur_y=`xdotool getmouselocation | cut -d ' ' -f 2 | cut -d ':' -f 2`
done
echo "4quadrant"
cur_x=`xdotool getmouselocation | cut -d ' ' -f 1 | cut -d ':' -f 2`
cur_y=`xdotool getmouselocation | cut -d ' ' -f 2 | cut -d ':' -f 2`
circle_x=$cur_x
circle_y=`echo "$cur_y-$RADIUS" | bc -l`
for ((i = 270; i <=360; i += 5)); do
tmp=`echo "scale=10;$i*3.1415926/180" | bc`
new_x=`echo "scale=10;$RADIUS*c($tmp)+0.5" | bc -l`
new_y=`echo "scale=10;$RADIUS*s($tmp)+0.5" | bc -l`
new_x=${new_x%%.*}
new_y=${new_y%%.*}
if [ -z $new_x ];
then
if [[ $new_x -lt 1 ]]
then
new_x=0
fi
fi
if [ -z $new_y ];
then
if [[ $new_y -lt 1 ]]
then
new_y=0
fi
fi
new_x=${new_x%%.*}
new_y=${new_y%%.*}
new_y=`echo $(($new_y*-1))`
new_x=`echo "$circle_x-$new_x" | bc -l`
new_y=`echo "$circle_y+$new_y" | bc -l`
new_x_offset=`echo "$new_x-$cur_x" | bc -l`
new_y_offset=`echo "$new_y-$cur_y" | bc -l`
xdotool mousemove_relative -- $new_x_offset $new_y_offset
sleep 0.001
cur_x=`xdotool getmouselocation | cut -d ' ' -f 1 | cut -d ':' -f 2`
cur_y=`xdotool getmouselocation | cut -d ' ' -f 2 | cut -d ':' -f 2`
done
echo "draw finish!"
运行:
给予脚本可执行权限,直接运行即可!