pyautogui可以用来防止windows锁屏吗? [英] Can pyautogui be used to prevent windows screen lock?

查看:73
本文介绍了pyautogui可以用来防止windows锁屏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用此脚本来防止 Windows 屏幕锁定.该脚本适用于移动鼠标,但不会阻止 Windows 10 锁定.

I tried to use this script to prevent windows screen lock. The script works for moving the mouse, but it doesn't prevent windows 10 from locking.

import pyautogui
import time
import win32gui, win32con
import os

Minimize = win32gui.GetForegroundWindow()
win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE)

x = 1

while x == 1:
    pyautogui.moveRel(1)
    pyautogui.moveRel(-1)
    time.sleep (300)

推荐答案

是的,可以.但遗憾的是不是通过移动鼠标,我不知道为什么并且想知道.所以,我的建议是尽可能使用 pyautogui KEYBOARD EVENTS.我已经通过使用 VOLUME-UP & 解决了我的问题VOLUME-DOWN 键.下面提供了示例代码:

Yes it can. But sadly not by moving mouse which I don't know why and would like to know. So, my suggestion is to use pyautogui KEYBOARD EVENTS if possible. I have solved my problems by using VOLUME-UP & VOLUME-DOWN keys. Example code is provided below:

import pyautogui
import time

while True:
    pyautogui.press('volumedown')
    time.sleep(1)
    pyautogui.press('volumeup')
    time.sleep(5)

如果需要,您可以使用任何其他键.

You can use any other keys if you want.

这篇关于pyautogui可以用来防止windows锁屏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆