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

后端 未结 8 740
小鲜肉
小鲜肉 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:09

    You can get the window on top, when the session is locked, the function return 0.

    import ctypes
    user32 = ctypes.windll.User32
    
    def isLocked():
        return user32.GetForegroundWindow() == 0
    

提交回复
热议问题