If you know babylon translation tool you'd know its word capture feature - when you right click on a word - it tanslates it (from a browser or any documtent).
I want to get the same tool - what program language should i use ?
The os i want to get it work on is win-xp and ubuntu. and I'm writing my program in java.
if it could happen from a java program it would be great.
thanks,
Adi.
You are facing two (IMHO) insurmountable challenges:
Windows and Linux use completely different mechanisms for displaying text on screen. Translating mouse positions into actual text is pretty darned difficult. This is hard even if you're targeting a single operating system.
Java apps generally run in a sandbox, i.e., they can't just go mucking around in the OS asking other windows to tell them what text is under the mouse, nor can they override the default right-click action windows they don't control.
A better UI approach would be something that uses the system clipboard, which I think is available to Java on all systems (I'm not a Java guy, I'm not sure). So, the user would copy a word in any window, perhaps hit some sort of global shortcut key (again, assuming you can assign one in a Java app), and the Java app could access the word in the clipboard and do what it needs to do.
Related
Sorry, this question is pretty broad, but I haven't a clue how to go about it.
In Java, how can I get whatever a Windows application is displaying in the form of an Image?
I'd like the contents of the Image to include just a frame from one application window, not a whole monitor.
I think getting the application window from the title of the window may be a start, but does Java even have access to the GUIs of other processes?
The best you can do in pure Java is to use the Robot class to capture a specified rectangle. The following Q&A show how ... for the case where the rectangle is the entire screen.
Screenshot capture in Window 8 OS
(This should work for all non-headless Java SE platforms.)
That's the easy bit. The hard bit is figuring out what rectangle to screenshot. The Java libraries provide no APIs for finding information about the screen locations of "other" applications. To find that kind of information, your Java application would need to interact with the native OS via a native library or an external utility command. This will inevitably be platform specific ... meaning that it will break for Mac and Linux, and possibly for other versions of Windows as well.
I wouldn't try to do this in Java at all. Instead, I would look for an OS-specific screenshot application that can be run as an external application; e.g. using Process.exec. Alternatively, I'd figure out how to write such an app, in (say) C#.
I think getting the application window from the title of the window may be a start, but does Java even have access to the GUIs of other processes?
Nope and nope.
I've just learned Java SE basics and want to make a utility program that popups a small window when selecting a text and when click the small window the selected text is converted to another equivalent characters in other language.
I wrote a class that should take any selected text from windows and convert it to the targeted language, how can I configure my app to windows backend to allow my program take the text as parameter?
You can't -- not with core Java, since the key functionality that you're looking for, for the program to be able to listen to user interaction with other programs and the OS, is something that Java was not built to do. One of Java's prime directives from the very beginning was to be able to run on multiple platforms, and in order to achieve this, the creators made the language and its tools as OS agnostic as possible, and so tasks that require a close integration with the OS don't work well with Java.
I'd suggest using JNA or JNI which would allow your Java program to make OS calls including mouse and keyboard hooks, or integrating another tool such as an OS scripting tool into your Java program via processes/streams.
I am looking for a way to mimic operating-system (Windows in specific) actions through Java. Preferably, the program should run in the background, but it is not a big deal if it does not. I got the background part covered thanks to this question. I was looking for the following specific features :
Maximizing/Minimizing the currently active window. (Can be any window, not just the Java application window.)
Closing the currently active window.
Open installed programs, and system utilities like the calculator, paint, etc. (I figured out this one from this question.)
Shutdown/Restart (This one's done too, thanks to the question here.)
So, my actual question is:
Is it possible to minimize/maximize or close an application window from a java program? (in Windows)
Example Scenario:
Firstly the java program is started, and it runs either as a background process or as a window. Bottom-line is that it should be able to accept triggers like maybe a keyboard shortcut or microphone input to trigger the action. After that suppose a Chrome window is opened and is currently active. Now on pressing the pre-defined shortcut, the Chrome window will minimize/maximize or close.
If the answer to the question is yes, I could use some pointers to start with my application. Thanks!
What you need is like an OS shell programming interface.
In Java side you will define a few interfaces.
Another Java layer will detect which OS is used and will return an implementation of interface: Windows, Linux, Macosx.
Some functionality you can have with simple bash command: in windows cmd, in linux .. to many. Eg shut down, launch MSPaint, Calculator.
Other functionality you can have it with windows API: you will need to write some JNI functions and call it. eg minimize, maximize. It is possible.
Edit:
I see there is no accepted answer, although it is answered properly.
Here is a C# code which does what you need in Java.
Now you need to migrate this code to Java:
In your java class declare a function:
private native maximizeOrMinimizeWindowWithName(String windowName, boolean maximize);
Compile -it
use Javah.exe - it will generate the necesary .h files
Use a C editor, configure environment, use the generated .h file.
-include windows api headers
-load user32.dll
- do more stuf..
compile your C code to .dll
put the your.dll into your app PATH environment variable. ( windows has the . in path, linux not)
-text, bugfix,
for more info you should see a basic JNI tutorials.
-upvote accept :)
This can be initiated from Java, but not actually implemented in Java. In other words, it will take a lot of platform-specfiic JNI library code to get it working.
Java will give you almost no benefit for your use case; you should avoid it altogether for this project.
You should look into Autohotkey. It's an system dedicated to simulate user programmaticly.
Using AH scripts you can easily access all open windows, installed programs and even control mouse and keyboard.
First of all, I'm a java developer and I am currently working on a small application for Windows only.
In my application, I wish to do as dropbox or tortoise do : add an overlay icon in windows explorer to show the user some state of files managed by my application. (I want the icon of the file change depending on some data stored in the file)
Is it possible to do so in Java ? Do you have examples ?
If it is doable but not efficient, how would you do instead ?
Thanks in advance
Fluminis
It would be possible to do this via JNI - you would need to hook into the Windows registry and from there into the Explorer shell, probably into the various file classes held there.
However, unless you have at least some familiarity with C++ and the windows API, you are unlikely to be able to achieve this.
Java is not the ideal language for what you want to do.
I want to automate an external application, but I have several problems:
How can I recognize a button or other field of an external application in Java?
I use the Robot class in Java for making notepad automation where I open notepad, select file menu, and save or exit, etc.
The problem is, it needs X,Y coordinates for the mouse pointer to go to the proper location.
I want to make it more dynamic, i.e. it should recognize the file menu of a running notepad anywhere on the desktop.
How can this be done in Java? Is there any class in Java I can use to do this?
Thanks everyone to give me response, I want to be more specific i want to know how can i make ui automation by using any tool if it is not possible in java or using any api of java.automation tool must be freeware.....i am searching net for that i found AutoIt is like that.But if any one do this type of things please share his/her experiance means is it possible to do that in AutoIt or not possible if not then which tool do that kind of things.
It is easy to integrate Sikuli into a Java-application since it is written in Java. Sikuli uses image recognition to find elements visible on the screen like buttons and such. It is very easy to use and provides an alternative for tasks that are difficult to handle with static positioning, like finding moving windows and such.
Take a look at this: http://sikuli.org/docx/faq/030-java-dev.html
Hope this helps!
You should have a look at Sikuli. It takes as inputs images of the ui elements to select an area in the targeted app. It's a UI Automation Application
That's a bit difficult to install (at least on Debian/Ubuntu, where I tested it), as you'll need a recent version of OpenCV, a particular version of JXGrabKey but the quality of the program worth the trip. Good Luck
Java doesn't have an API to examine the UI of another application; that would be a very big security risk.
Which is why the Robot class can only record events (key presses, mouse movements and clicks) but not which UI element was involved in most cases.
It would be possible to do more if the external application was written in Java because then, you could analyze the objects in memory but for obvious reasons, this isn't possible for C++ or .NET applications.