aspose file tools*
The moose likes Java in General and the fly likes Process... How in depth can I control it ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Process... How in depth can I control it ?" Watch "Process... How in depth can I control it ?" New topic
Author

Process... How in depth can I control it ?

Tomer Gal
Greenhorn

Joined: Dec 18, 2004
Posts: 24
Hi guys, I'm writing some automation application, therefore I've got a couple of questions regarding the extent of control one has when writing it with only native Java.



After creating a process and running it , can I minimize/maximize it ?
Can I make it the active window ? ( i.e focus on it )
Also, the "noetpad" application which is being run is the code I've pasted above - Can I send it key strokes after creating it ? ( I've managed to send text to console applications but couldn't do the same on notepad )

Thanks in advanced
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I'm not experienced in this, but without native methods, my expectation is that once you launch the application (with whatever parameters you're able to pass in the exec method), it's on its own -- outside the reach of the JVM.



"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Tomer Gal
Greenhorn

Joined: Dec 18, 2004
Posts: 24
marc weber, perhaps yes and perhaps not...
The reason which makes me think it might be possible is that Java got a minimal control on the thread of the process which was executed -
You can use the Process destory() method to kill that process. So maybe it has ability to minimise/maximise it also.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You might be able to use java.awt.Robot to send mouse and keyboard events to Notepad. I have not used this class, but it seems like it is will be difficult to use it in a general way. I think you will need to know the exact location of the Notepad window and its menus and buttons. However, it might be worth looking into it.

Layne


Java API Documentation
The Java Tutorial
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42276
    
  64
You say that it's supposed to be all-Java, but since you're trying to control notepad specifically, and that is Windows-only: The Jacob and Jawin projects (both on SourceForge) are bridges between Java and the COM world, so if COM were allowed, pretty much anything would be possible.


Ping & DNS - my free Android networking tools app
Tomer Gal
Greenhorn

Joined: Dec 18, 2004
Posts: 24
Thanks guys, I'll go to my workplace right now and try the things you've suggested.
I'll let you know what did the trick
Tomer Gal
Greenhorn

Joined: Dec 18, 2004
Posts: 24
Wow... this Robot class rocks!
Can move the mouse and press the keyboard, that's great.
Now there's one thing left for me to find out... How can I make a specific window active ?
What I mean is - for example when you press Alt + Tab and choose the window you'd like to open, I need to do the same thing in the program so I could do some automation.
Does anyone knows which Class if any can give me that kind of control ?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Have you tried sending an Alt-Tab key event using Robot? It seems to me like it should work since Robot accesses the OS's event queue directly rather than manipulating Java's event queue.

Layne
Tomer Gal
Greenhorn

Joined: Dec 18, 2004
Posts: 24
I Didn't try it as It wont help.
Lets say my application sent Alt + Tab and the list of windows appeared,
I wont be able to find the specific window I'm looking for as I Got no way of knowing which window I'm pointing at.
I Need the OS to tell me the names of those windows.
Eric McIntyre
Greenhorn

Joined: Mar 03, 2005
Posts: 26
You're into some deep OS integration issues at this point. AFAIK, there's no way to do what you're trying to do without making Win32 calls directly through JNI (or possibly indirectly thru Jawin).

Eric
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Tomer G.:
I Didn't try it as It wont help.
Lets say my application sent Alt + Tab and the list of windows appeared,
I wont be able to find the specific window I'm looking for as I Got no way of knowing which window I'm pointing at.
I Need the OS to tell me the names of those windows.


One possible solution is to run the program when no other windows are open. Of course, I don't know if this is entirely possible since I don't know the context of what you are doing.

Layne
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

In theory, you could write a kind of ocr-software, make a snapshot of the task-list, and find out by identifying the strings, which program has the focus.

In reality, you would have to deal with user-themes and different fonts, user-interrupts which prevent the snapshot to get the image of the taskbar fast enough, different looks of the taskbar for win3.11 to win2003 and probably more problems.


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Process... How in depth can I control it ?