How to get information from another running program?

4

Updated

I thought my question would get lost and honestly I did not even see it reopened. But taking advantage of that now there was a move to update on my app. It is being developed in C # and therefore for Windows (but I can change this by switching to C ++, but they are just plans).

Question

The specification : I need a function / procedure / library / anything that makes it possible for me to capture information from another open executable. The idea is that when my application and an emulator (such as ZSNES) are open, I can retrieve information from it, such as:

  • Whether the window is focused or not,
  • which keys were pressed (with my app obviously out of focus),
  • get the title of the window since I know the name of the process,
  • and, if possible, find out which game is being played (some emulators log one, others unfortunately do not)
asked by anonymous 07.09.2014 / 22:14

1 answer

1

This code below lists the processes that are being run by the Operating System:

import java.io.*;

public class Teste {
  public static void main(String[] args) {
    try {
      Process p = Runtime.getRuntime().exec("ps ax"); // comando que vai pegar os processos

      BufferedReader resultado = new BufferedReader(new InputStreamReader(p.getInputStream()));

      //mostra os resultados obtidos pelo comando "ps ax"
      String s;
      while ((s = resultado.readLine()) != null)
        System.out.println(s);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

Link to a site with further discussion in other languages: Detection Of Programs Running

    
25.09.2014 / 01:06