• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Tomer Gal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tomer Gal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic