Lets say i’m reading PDF file or using web broswer and i hilighted a word.
I want a procedure in JAVA , procedure in an independent program , to get that selected text
using my JAVA program.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It sounds as if the other program will be “active” and have focus, and that you are desiring to use Java in the background to capture the selected text, perhaps using a hotkey combination.
Java may not be the best tool for this sort of behavior. Since Java is built to be as OS-agnostic as possible, it is difficult to do OS-specific tasks with Java. Having said this, this can be done with Java but would involve “stretching” Java and using non-Java code integrated with Java via JNI, JNA, or a OS-specific utility bridge such as AutoIt V3 if this is for a Windows platform. This solution would of course be OS-specific and could not be used in a cross-platform fashion.
Edit 1
You state in a comment:
@blackgh: and therein lies the rub. You need to first learn JNI (more difficult if you’re not already familiar with C or C++) or JNA (which in my opinion is easier), and then learn to make a keyboard hook if you want to make a hot key. This would take a bit of time and effort to do, but is doable. If this were my project, and I needed to do it quick and it absolutely had to integrate with Java, and if it were for a Windows platform, I’d go with AutoIt V3 or something similar to create a script for the hot key as the easiest solution, and in fact I’ve done something like this, but again you’d need to learn the the AutoIt language (it’s like Basic).