Using pyautogui to unlock screen

白昼怎懂夜的黑 提交于 2020-02-25 05:41:13

问题


I'm using pyautogui to unlock my computer screen on Windows 10. Here's the script:

pyautogui.FAILSAFE = False
time.sleep(7)
print("Pressing 'space'")
pyautogui.press('space')
print("Waiting for 3 seconds.")
time.sleep(3)
print("Typying Password")
pyautogui.press('p')
time.sleep(0.1)
pyautogui.press('a')
time.sleep(0.1)
pyautogui.press('s')
time.sleep(0.1)
pyautogui.press('s')
time.sleep(0.1)
pyautogui.press('w')
time.sleep(0.1)
pyautogui.press('o')
time.sleep(0.1)
pyautogui.press('r')
time.sleep(0.1)
pyautogui.press('d)
print("Hitting 'enter'")
pyautogui.press('enter')
time.sleep(9)

The script does simulate the spacebar as my lock screen is shifted to the screen where it asks for the password but it doesn't type in my password. I wonder why? When I manually open my account, the output of the script confirms that it ran successfully. What could be the cause of it?


回答1:


Unfortunately, Windows specifically prevents automated scripts from running while the computer is locked as a security precaution, so you won't be able to send any keyboard presses to the login screen.

Something similar also applies to, for example, AV software that prevents simulated mouse clicks or keyboard presses to its windows. This prevents malware from disabling the AV software.



来源:https://stackoverflow.com/questions/51176112/using-pyautogui-to-unlock-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!