有没有办法在屏幕锁定时让脚本在 python 中运行?

问题描述 投票:0回答:2

我正在尝试使用 pyautogui lib 在我公司的 pyton 中运行脚本

所以我想:

  • 锁屏时继续运行脚本,因为我们要运行脚本并锁屏离开电脑

有人有什么建议吗?我试过编码

"pyautogui.hotkey('win', 'l')
但它没有用。

注意

--

import pyautogui
import time
import pyperclip
import PySimpleGUI as sg

pyautogui.FAILSAFE = True

Layout = [
[sg.Text("Por favor, insira o número de contas a serem canceladas")],
    [sg.InputText(key="contas")],
    [sg.Button("Iniciar"), sg.Button("Cancelar")],
]

Janela = sg.Window("Macro Encerramento Contas", Layout, margins=(100,50))

while True:
    evento, valores = Janela.read()
    if evento == sg.WIN_CLOSED or evento == "Cancelar":
        break
    if evento == "Iniciar":
        numero_contas = valores["contas"]
        x = int(numero_contas)
        pyautogui.PAUSE = 0.2
        with pyautogui.hold('alt'):
            pyautogui.press('tab', presses=2)
        pyautogui.hotkey('ctrl', 'c',interval=0.3)
        with pyautogui.hold('alt'):
            pyautogui.press(['tab', 'tab', 'tab'])
        time.sleep(0.5)
        pyautogui.press('tab')
        time.sleep(0.5)
        pyautogui.hotkey('ctrl', 'v', interval=0.25)
        pyautogui.press('tab', presses=3)
        pyautogui.press('enter')
        for i in range(x-1):
            pyautogui.leftClick(884, 5)
            pyautogui.press('down')
            pyautogui.hotkey('ctrl', 'c')
            with pyautogui.hold('alt'):
                pyautogui.press('tab')
            time.sleep(0.15)
            pyautogui.press('tab')
            pyautogui.press('enter')
            pyautogui.press('tab')
            time.sleep(0.15)
            pyautogui.hotkey('ctrl', 'v', interval=0.15)
            pyautogui.press('tab', presses=3)
            pyautogui.press('enter')
            time.sleep(0.1)


#pyautogui.press('tab',presses=3)
#pyautogui.press('enter')
pyautogui lockscreen
2个回答
0
投票

只要 PC 没有进入睡眠状态,您的脚本就应该继续运行——无论屏幕是否锁定。

如果我们正在谈论使用 Python 锁定屏幕,您可以尝试这样做:

import ctypes
ctypes.windll.user32.LockWorkStation()

为了防止你的电脑进入睡眠你可以使用wakepy

from wakepy import keepawake
with keepawake(keep_screen_awake=False):
  ... # do stuff that takes long time

0
投票

你找到解决方案了吗?我也遇到了同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.