Is it possible to get image contents of an obstructed window without bringing it to the front? Also, is it possible to send mouse clicks to a specific locations of such window? I want to do this in Java, using JNA, running Windows XP (if it is possible, would it also work on Windows 7?). If that can be done, would you mind telling me what functions will be needed and where can I read about it, because I have never worked with JNA yet. Thank you.
Related
This is going to be a bit convoluted, and likely seem a bit pointless to many (if not all) of you.
I use Windows 7, mostly, though XP is also used.
I have a KVM, it accepts keyboard and mouse input, and is networked so that I can remotely input via mouse and keyboard. However, I wish to copy and paste text (even modifiers, such as alt, ctrl, and so forth).
The onscreen keyboard is fine for...you know, keyboarding, but I want to send keys (much like VBS does) through copy and paste.
At this time I've made a little VB script that lets me do this, but it has some extreme limitations, primarily in that it doesn't STOP once you get going. If the window looses focus, or it does something unexpected, bad things happen.
Imagine putting a line of commands that are meant to control a Windows computer, remotely, and it just control your terminal, because the window lost focus. I have no difficulty in giving the right window focus in the code, but a simple slip of the hand will break it. Ideally, I would only be sending those keystrokes to THAT window, regardless of what window is active.
I have been unable to find a way to do that through VBS, though perhaps it exists. I could simply loop, forcing that window to go active for each keystroke, but that doesn't ALWAYS work, as I sometimes need to use key combos, and I have no idea how I'd send an %{f4} one character at a time and still make it work.
So, finally, here's the question: How can I copy and paste test into a text field so that it ALWAYS goes to the window I want it to go to? Preferably it'll be usable in other windows (may have more than one instance open), should I want to do that, and it should be able to go a certain typing speed, as the application I use does crash if you send too much data at once (unclear how much is too much, but a single line is usually fine).
This isn't all that different from using a macro program, but I will be severely limited in what sort of application I can use. Scripts or java apps are about all I can get away with.
Thanks in advance!
I need to add a functionality in my application that would require me to know when the user changes window (it could be a browser window, my application's window or any other window).
Ideally, it should be possible for me to print the window's title when it gets focus. The problem I'm having finding a solution to this problem is that I only get links that tell me how to add a focus listener on windows I'm creating, which I already know how to do and doesn't help me in the slightest.
The solution should at least work on Windows 7.
The (major) problem you face is that Java filters system events so that you can only recieve events that are related to you. AFAIK this is all done at a native level, so there's no way to intercept or modify this filtering process.
The only solution is to create another "event loop" using JNI/JNA which will allow you to intercept the event messages being passed about the system and handle them the way you want to.
While slightly more complicated, it does open up a world of opportunities...
I have a java Robot program ,where it can type a word on notepad,word etc,.
But the problem is i am not getting focus of window application, when i tried to enter the cursor in its textbox manually by using ALT-TAB,
And the application is not available in the list ,while doing ALT-TAB ,
also it is not visible in Task Manager-> Application tab
but, it is available with Processes tab of Task Manager.
Is there any solution to get focus of that windows application for keyPress using Java Robot.
Also ,in some other PC's ,i am getting Clear Focus of the application when i put the cursor manually after running the java robot program. I have installed JDK1.6 in all my PC's. It is not working only in my PC's.
Thanks in advance!!
I think that your best bet is to use JNA to allow you to make system calls.
Assuming a Windows program, you could use JNA to make calls to the user32.dll including dll functions such as FindWindowEx(...) and SetForegroundWindow(...) to set the window of your choice to the foreground.
Instead of getting the focus of the other app, you could put your robot to the background, returning whatever was in the foreground previously (ie your target app) to get the focus.
I'm trying to find a concrete yes for some assumptions I have about developing a Java Swing app to be run on a Windows tablet device (I believe it'll be running Windows XP). We have a demo we are writing and we're leveraging previous experience with Java Swing to write the UI and I just want to make sure that touch events in Windows are treated like mouse clicks, is this true? Does anyone have any direct experience writing Swing apps for Windows tablets? The target device is http://www.amazon.com/Promotion-X70EX-3GP-Accessory-Standard/dp/B002MZZX76.
Also, wondering if the soft keyboard will automatically be activated when focus is given to a JTextField and other Swing data entry fields.
Thanks!
We developed an application in Swing which runs well on Windows XP tablets. Yes, touches are treated just like mouse clicks. However, I can only confirm this for basic touch events, e.g. clicking on a button. I can neither confirm nor deny whether they work for more complex gestures.
As for the soft keyboard, I cannot remember whether this works or not. In the end our users ended up using the tablet just like a regular laptop, i.e. with the keyboard not the touch screen. This is mostly due to the amount of text they need to enter in the application.
I am developing a screen capturing utility in Java & I want to capture any background window, when I click on that particular window. But I am not getting how to add mouseClicked event to background window. Can somebody please help me?
I may be way off base but if the other window is not a Java window then it should be outside the Java sandbox. To interact with it requires a native API which is anathema to Java.
Quite obviously as it is you can't interact with other application windows. It can be any random window in your case I presume. Therefore, your mouselistener approach is not correct.
Rather, try to approach it like fetching pixel information displayed on the screen. There is an awt package java.awt.Robot or something that could be used for your purpose. If you want to implement capturing of active window then see if there are java APIs to interact with O.S. and get information of current active window and it's pixel co-ordinates. The co-ordinates could then be supplied to the rectangle attribute that is used with java.awt.Robot APIs to define screen capture area.
If that window is not part of your application you can't do much with it.
Otherwise you just have to add the mouse listener to that window too.
What's your situation?
java.awt.Robot has a method createScreenCapture(Rectangle screenRect) to capture screenshots.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Robot.html
however, to get the current active window you would have to use OS specific extensions (mostly via JNI)