如何确定屏幕保护程序是否在Java中运行? [英] How to determine if a screensaver is running in Java?

查看:130
本文介绍了如何确定屏幕保护程序是否在Java中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序定期在屏幕上显示信息。但是如果屏幕截图处于活动状态,则应用程序应该等到用户返回。

My Application periodicly shows information on the screen. But if the screenshot is active, the application should wait until the user returns.

有没有办法确定屏幕保护程序是否正在运行?

Is there any way to determine if the screensaver is running?

我不需要一个干净的解决方案,你只需要在windows xp上工作。

I don't need a clean solution, u just needs to work on windows xp.

类似的问题,但其他技术:
如何确定屏幕保护程序正在运行?

Similar question, but other technology: How to determine that a screensaver is running?

推荐答案

尝试使用 JNA 库调用 SystemParametersInfo 系统调用。

Try using the JNA library to invoke the SystemParametersInfo system call.

以下示例使用来自的代码由JNA提供的win32示例

public class JNATest {

    public static void main(String[] args) {
        W32API.UINT_PTR uiAction = new W32API.UINT_PTR(User32.SPI_GETSCREENSAVERRUNNING);
        W32API.UINT_PTR uiParam = new W32API.UINT_PTR(0);
        W32API.UINT_PTR fWinIni = new W32API.UINT_PTR(0);
        PointerByReference pointer = new PointerByReference();

        User32.INSTANCE.SystemParametersInfo(uiAction, uiParam, pointer, fWinIni);

        boolean running = pointer.getPointer().getByte(0) == 1;

        System.out.println("Screen saver running: "+running);
    }
}


public interface User32 extends W32API {

    User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class, DEFAULT_OPTIONS);

    long SPI_GETSCREENSAVERRUNNING = 0x0072;

    boolean SystemParametersInfo(
        UINT_PTR uiAction,
        UINT_PTR uiParam,
        PointerByReference pvParam,
        UINT_PTR fWinIni
      );


}

这篇关于如何确定屏幕保护程序是否在Java中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆