views:

379

answers:

2

Is it possible to make Java program that will determine the absolute position (x,y on screen) of blinking keyboard cursor? That cursor can be in any text editor.

+2  A: 

Not easily, since the position of a cursor on a screen of a program is merely a data point inside that program and rendering that cursor is a method running in the program. (I'm reading your question to mean that the program/editor in question is a wholly separate process from your Java program, right?)

You can theoretically do it if:

  • The program explicitly exports via some API calls the cursor location

  • You capture the actual screengrabs of that program very fast, analyze the image difference, and deduce cursor location from appearing/disappearing rectangle or short line in case the screen of the program didn't change save for cursor blink.

    • If you need relative (e.g. in # of chars instead of # of pixels) location in an editor, then somehow use edge recognition to detect editor size, some advanced image processing magic to deduce font size, and compute character-based offsets.
  • If the editor is using standard OS (e.g. Windows) APIs to draw both editing window AND the cursor, it might theoretically be plausible to hook into the system to intercept those calls - i don't posess nearly the amount of knowledge of what those APIs might be or if such even exist, how possible it is to intercept them, and whether Java programs are able to do that even if it's possible theoretically.

DVK
Are you sure? Position of cursor is system property I think. Look how this program can determine position: http://www.deepskyblue.net/software/sanvient/en/
dede
I'm not quite sure what that thing does - can you please descrive the exact functiionality that you are referring to? The manual's pretty thin
DVK
You can download sanvient and see what I mean, it's simple clipboard utility (and no, it's not virus, trojan blah, blah!). For example, when you press CTRL+E sanvient place it's window right above input cursor no matter in what application it is. So if I'm in notepad and hit CTRL+E sanvient place it's window right above cursor.
dede
+1  A: 

The question here is not whatever is possible or not, the question is for what purpose should i want to do this? Frankly, i don't see any reason, and i am sick of annoying mini-apps who act like spyware. Are u trying to duplicate the existent app into another form of mass terror? I beg your pardon if u find my comment offensive, but this is my answer. Another question : why?

Hypercube
Well it is far away from virus, spyware, terror etc. I'm trying to make some developer's utility for Adobe AIR community, but I need some java features so I can integrate it with Merapi project.
dede