Created
November 20, 2021 07:24
-
-
Save gsw945/9ca6cef280a84333d274d800e3562c57 to your computer and use it in GitHub Desktop.
screen-keep-alive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# sudo apt-get install python3-tk python3-dev | |
# pip install pyautogui | |
import time | |
import pyautogui | |
print('自动移动鼠标,避免锁屏') | |
print('按 [Ctrl + C] 退出') | |
print('-' * 60) | |
screenWidth, screenHeight = pyautogui.size() | |
print('屏幕尺寸: {0} x {1}'.format(screenWidth, screenHeight)) | |
pyautogui.FAILSAFE = False | |
pyautogui.moveTo(screenWidth // 2, screenHeight // 2) | |
step = 20 | |
dirX = 1 | |
dirY = 1 | |
while True: | |
pyautogui.move(step * dirX, step * dirY) | |
currentMouseX, currentMouseY = pyautogui.position() | |
if currentMouseX >= screenWidth - step: | |
dirX = -1 | |
elif currentMouseX <= step: | |
dirX = 1 | |
if currentMouseY >= screenHeight - step: | |
dirY = -1 | |
elif currentMouseY <= step: | |
dirY = 1 | |
time.sleep(0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment