Detecting if the screensaver is active and/or the user has locked the screen in Windows

前端 未结 6 1051
遇见更好的自我
遇见更好的自我 2020-12-09 06:50

I\'m writing an app that at times will send notifications to the user in the form of toaster messages.

If the user is not there, he can\'t see the notification. So w

6条回答
  •  攒了一身酷
    2020-12-09 07:12

    There is no documented way to find out if the workstation is currently locked. You can however get a notification when it un/locks. Subscribe the SystemEvents.SessionSwitch event, you'll get SessionSwitchReason.SessionLock and Unlock.

    The sceen saver is troublesome too. Your main window gets the WM_SYSCOMMAND message, SC_SCREENSAVE when the screen saver turns on. You can pinvoke SystemParametersInfo to check if it running. You'll find sample code for this in my answer in this thread.

    There is no good way to find out if the user fell asleep.

提交回复
热议问题