且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检测如果屏幕是活动和/或用户已经锁定屏幕在Windows

更新时间:2023-11-14 12:49:10

有没有记录办法找出如果工作站当前被锁定。然而,你可以当它UN /锁得到通知。认购SystemEvents.SessionSwitch事件,你会得到SessionSwitchReason.SessionLock和解锁。

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.

sceen保护程序麻烦了。屏幕保护程序打开时你的主窗口获取WM_SYSCOMMAND消息,SC_SCREENSAVE。你可以的PInvoke SystemParametersInfo来检查它是否运行。你会发现此示例代码在我的答案中的这个线程

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.