I want to make simple java program that will insert some text into current cursor position. That cursor position can be in any text editor, for example notepad. Is this possible?
Using this article as a base about copy/paste, you may see that you can only put something to the clipboard but not directly changing the content of a foreign's process Textbox.
You might want to get the window handle of the box and send a message to it using the Windows API. This works on windows only, I don't know whether there's an equivalent way on Mac OS / Linux. Maybe this doesn't even work directly from java. You would need to type some C/C++-code and use the Java Native Interface (JNI)
regards
If u are asking for the current cursor location, i think u should use this :
Display.getCurrent().getCursorLocation()
Having the cursor location, what to do next requires further details. If u want to automatically write some text into foreign applications like Word or Notepad, this sounds more like a virus to me..
It's a hack, but look into java.awt.Robot. It lets you programmatically make mouse clicks and key presses, among lots of other useful things. So one way to do it would be:
- Use Atmocreations' article to put text in the clipboard
- When you want to paste it, use Robot to click at the current position (if you need to give that field focus)
- Use Robot to press Ctrl-V (or whatever your system expects for a paste)
Like I said, it's not at all a clean solution, but it will work in a pinch.