1
votes

I am trying to create an app similar to spy++ in java, in which I can get class/caption/handle of every element which I am taking mouse over. e.g. :

  1. If we move mouse on task bar, the spy tool shows the info as : Handle : 000100AA Caption : Running applications Class : MSTaskListWClass
  2. If we take mouse on one of the button of windows calculator(lets say "1") spy tool will show caption : 1

I m already getting foreground window with following code:

GetWindowTextW(GetForegroundWindow(), buffer, MAX_TITLE_LENGTH);

and process name :

Pointer process = OpenProcess(PROCESS_QUERY_INFORMATION
                | PROCESS_VM_READ, false, pointer.getValue());
        GetModuleBaseNameW(process, null, buffer1, MAX_TITLE_LENGTH);

But i am still not able to get captions and classes for buttons/textboxes. Please help to do the same.

1
Java is a very, very poor choice for this, because you need native code extensively. - Joey
Welcome to Stack Overflow. We like it better if you show what (code) you have tried. See How do I ask a good question?, for guidance. - andy256

1 Answers

0
votes

The following answer is for mouse click event.

Use jnativehook to handle a global mouse click event. When the user clicks, find out the foreground window and its position.

You have to create a dll which will have the native winapi calls. Then load this dll in your java program.

  1. First get the global mouse position with jnativehook's nativeMousePressed.
  2. Find the handle for the foreground window .
  3. Get the location & process id from the handle.