Is there a way for a Java application to detect if the screen is locked?

后端 未结 2 712
我寻月下人不归
我寻月下人不归 2021-02-14 21:43

I\'m looking for a way to know in a Java application (without JNI - it\'s a multi-platform application) can detect if the screen is locked.

For information... o

2条回答
  •  北海茫月
    2021-02-14 22:09

    I confirm there seems to be no Java API to detect a screen lock status.

    Spark developer gave it a try in 2006 (like this thread shows), but without giving out any details on the specific of the implementation.
    However, it is likely it involved JNI and native call to functions like WTSQuerySessionInformation (To detect if disconnected use WTSQuerySessionInformation(NULL, WTS_CURRENT_SESSION, WTSConnectState) and look for WTSDisconnected).

    So, as Michael pointed out, there is no "multi-platform" universal answer (to the best of my knowledge).

提交回复
热议问题