电脑如何保持屏幕常亮(移动鼠标)
由于工作需要,电脑需要保持常量,但无法通过设置电源计划实施时,不定时移动鼠标是一个不错的方案。
具体实施如下:
1、创建一个bash脚本,并赋权
chmod +x aaa.sh
2、粘贴代码:
#!/bin/bash
#初始化变量
lastx=0
lasty=0
counter=0
#死循环
while true; do
#获取当前鼠标位置
location=$(xdotool getmouselocation 2>/dev/null)
currentx=$(echo "$location" | sed -n 's/x:\([0-9]\+\).*/\1/p')
currenty=$(echo "$location" | sed -n 's/y:\([0-9]\+\).*/\1/p')
#判断是否移动
if [ "$currentx" -eq "lastx" ]; then
((counter=counter+10))
else
counter=0
lastx="$currentx"
lasty="$currenty"
fi
#3分钟鼠标未动,则自动移动鼠标
if((counter>=180)); then
randomx=$((RANDOM % 100))
randomy=$((RANDOM % 100))
#移动鼠标,并更新位置
xdotool mousemove --sync "$randomx" "$randomy"
lastx="$randomx"
lasty="$randomy"
counter=0
fi
#10秒判断一次
sleep 10
done
3、运行
sh aaa.sh