How to avoid lock screen under Win10 via Python code?

73 Views Asked by At

A Win10 system locks the screen after a certain time of inactivity.

I know:

  • you could change the Win10 settings or
  • install special software which claims to avoid stand-by or lock screen

However, I cannot/don't want to change settings nor install other software. Well, I could attach a mechanical device to the mouse and move it every once in a while. Hmm, seems to be too complicated.

I thought I could move the mouse by a little 7-liner Python program.

Code:

import mouse, time

for i in range(10000):
    print(i)
    mouse.move("20","20")
    time.sleep(60)
    mouse.move("150","150")
    time.sleep(60)

This moves the mouse every minute between two positions. However, if I run this Python code in a Windows console, the screen nevertheless gets locked after a while.

Maybe somebody can explain:

a) whether avoiding lock screen is possible at all by such a method or if Windows is preventing this?

b) if it could be done via a few Python lines, what would be the conditions and the code to get this to work?

0

There are 0 best solutions below