Detect OS Sleep and Wake Up events in Java

前端 未结 3 416
礼貌的吻别
礼貌的吻别 2020-12-16 18:40

Is there a way for a Java program to detect when the operating system is about to go to sleep, or failing that, at least detecting a wake up?

The actual problem is t

3条回答
  •  抹茶落季
    2020-12-16 19:04

    You could just JNI or JNA to trap the sleep/wakeup events from the OS.

    From Windows Power Events (MSDN), you would have to create a Window handler and a null window to receive the WM_POWERBROADCAST events. This window procedure could then call an event function in your Java code to bubble the message up.

提交回复
热议问题