Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
432 views
Welcome To Ask or Share your Answers For Others

1 Answer

Well, this is absolutely not clean, but it works as a dirty workaround:

I checks if 'any' screensaver (which have .SCR suffix) is running.

  private static boolean isScreensaverRunning() {
    List<String> p = WindowsUtils.listRunningProcesses();
    for (String s : p) {
      if (s.endsWith(".SCR")) {
    return true;
      }
    }
    return false;
  }

  public static List<String> listRunningProcesses() {
    List<String> processes = new ArrayList<String>();
    try {
      String line;
      Process p = Runtime.getRuntime().exec("tasklist.exe /fo csv /nh");
      BufferedReader input = new BufferedReader
      (new InputStreamReader(p.getInputStream()));
      while ((line = input.readLine()) != null) {
      if (!line.trim().equals("")) {
          // keep only the process name
          line = line.substring(1);
      processes.add(line.substring(0, line.indexOf(""")));
      }

      }
      input.close();
    }
    catch (Exception err) {
      err.printStackTrace();
    }
    return processes;
  }

Source of listRunningProcesses: http://www.rgagnon.com/javadetails/java-0593.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...