title: Check if the Windows screen is locked
body: <p>Is there a way to auto-check if the current user locked his PC? (usually activated by <code>Win+L</code>). One hacky method I see is somehow catch all key combinations, but then the question is how to know that the user has returned? </p>
  
  <p>Maybe there is some flag that can be accessed through python or windows terminal?  </p>
  
  <p>EDIT: I tried the code from here: <a href="https://stackoverflow.com/questions/26599462/detect-when-computer-is-unlocked-windows">Detect when computer is unlocked Windows</a></p>
  
  <p>It detects when screen is locked, but not when it's unlocked, it continues to write "Screen is still locked" indefinitely. So what can be the problem? I have Python 3.4, 64-bit Win7. </p>
  
  <p>EDIT2: Actually the <code>result</code> is always <code>0</code> for me, even without any locking, so in fact it doesn't detect anything.</p>
  
  <pre><code>import ctypes
  
  user32 = ctypes.windll.User32
  OpenDesktop = user32.OpenDesktopA
  SwitchDesktop = user32.SwitchDesktop
  DESKTOP_SWITCHDESKTOP = 0x0100
  
  hDesktop = OpenDesktop ("default", 0, False, DESKTOP_SWITCHDESKTOP)
  result = SwitchDesktop (hDesktop)
  
  print(result)
  </code></pre>