我正在尝试使用 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')
只要 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
你找到解决方案了吗?我也遇到了同样的问题