I recently discovered application Textify, that can copy un-selectable text on any window and save it to the clipboard. Is there any Java library, that provides you e.g. read all the text from another window? Or something like an API that could do this?
Asked
Active
Viewed 1,119 times
1 Answers
1
Of course it is possible. You can use Java Native Access (JNA) to achieve your goal: https://github.com/java-native-access/jna
Here is a sample code:
interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
int WM_SETTEXT = 0x000c;
int WM_GETTEXT = 0x000D;
HWND FindWindowA(String lpClassName, String lpWindowName);
HWND FindWindowExA(HWND hwndParent, HWND hwndChildAfter, String lpClassName, String lpWindowName);
LRESULT SendMessageA(HWND editHwnd, int wmGettext, long l, byte[] lParamStr);
int GetClassNameA(HWND hWnd, byte[] lpString, int maxCount);
}
public static void main(String[] args) {
User32 user32 = User32.INSTANCE;
HWND notePadHwnd = user32.FindWindowA(null , "About Calculator");
HWND editHwnd = user32.FindWindowExA(notePadHwnd, null, "SysLink", null);
byte[] lParamStr = new byte[512];
user32.SendMessageA(editHwnd, User32.WM_GETTEXT, 512, lParamStr);
System.out.println("Text from external window: " + Native.toString(lParamStr));
}
and the output is:
Text from external window: This product is licensed under the <A>Microsoft Software License Terms</A> to:
Of course you can do a much more with this library. Spy++ tool might be useful and some knowledge of c/c++. You should also check WinApi documentation.

Planck Constant
- 1,406
- 1
- 17
- 19