In Python 3, how can I tell if Windows is locked?

后端 未结 8 739
小鲜肉
小鲜肉 2021-01-13 11:27

How can I check whether a Windows OS workstation is locked? (e.g. Win+L or choosing the lock option after Ctrl+Alt+Del.)

I want something like ctypes.windll.us

8条回答
  •  [愿得一人]
    2021-01-13 12:24

    Hi Check these 4 lines..

    returns the application name which is on the screen.. if window is locked returns the string - Windows Default Lock Screen.

    from win32gui import GetWindowText, GetForegroundWindow
    import time
    time.sleep(5)
    # lock the system or open the application for a check
    print(GetWindowText(GetForegroundWindow()))
    

提交回复
热议问题