Re: image capture

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: image capture

Gabriel Landini
> mmh, that indeed sounds like a similar problem as the one that I have.
> Finally after playing with the code of the camera plugin, I managed to =
> run it each time that I need in an automatical way, but every time I =
> have to close it. I found out how to do automatically fortunately. but =
> it would be more useful to be able to have the plugin open while I run =
> my macro... with the alternative that I use,  for my purpose, that means =
> about 1000 times open and close the plugin in my macro... that's quite a =
> lot.=20

Does anybody know if this could be done within IJ?

If the plugin runs in a different thread, can one write a plugin that the only
thing it does is to locate the grabbing plugin window and emulate one click
on the necessary button?

Can anybody suggest a way of doing this?

Cheers,

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: image capture

Gabriel Landini
On Monday 26 June 2006 00:20, you wrote:
> It looks like this might be possible using Java's Robot class, even
> when you are trying to control a native (non-Java) application.
>
>      http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html
>      http://www.developer.com/java/other/article.php/2212401


Thanks Wayne, this is exactly what I was looking for.

I thought it would be also nice to make it able to send key presses too, but I
am struggling with the last bit:  how to convert a string into KeyCode...

If 'robotText' is a string that holds the text that the robot is suppossed to
send/type, the following does not output what I expected.

for (int i=0;i<robotText.length();i++){
        robot.keyPress( robotText.charAt(i));
        robot.keyRelease(robotText.charAt(i));
}

For instance if the string is "ABC-abc" the robot types:
"abc-123". I am obviously doing something wrong.

Any idea how to convert the char to KeyCode? (is the KeyCode what I need?).
Or do I have to make a table to parse the chars into KeyCodes?

Thanks in advance,

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: image capture

dscho
Hi,

On Mon, 26 Jun 2006, Gabriel Landini wrote:

> I thought it would be also nice to make it able to send key presses too,
> but I am struggling with the last bit:  how to convert a string into
> KeyCode...

I have not tested it, but this snippet could work:

-- snip --
import java.awt.event.KeyEvent;

[...]

String toSend = "ABC-abc";
KeyEvent e = new KeyEvent(null,
for (int i = 0; i < toSend.length(); i++) {
        char c = toSend.charAt(i);
        e.setKeyChar(c);
        int keyCode = e.getKeyCode();
        robot.keyPress(keyCode);
        robot.keyRelease(keyCode);
}
-- snap --

Hope this helps!
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: image capture

Albert Cardona
In reply to this post by Gabriel Landini
Gabriel,

Yes you can have a plugin running on its own thread that never returns (never
ends), and either use the Robot class to make clicks (your mouse pointer will
move too, which is undesirable), or directly execute the button -just capture
it by exploring down the Container classes. For example, from the WindowManager
get the window of the video, then lists its components, then for each one that
is a container (JPanel, etc) list its components, et cetera until you find the
button. Then "doClick()" on the button (if it's a JButton). It all may be
easier by creating a MouseEvent with the button as the object and passing it to
whatever object is the MouseListener (this is what java does internally
anyway).

Hope it helps.

Albert

--------------------------------------------------------------------
This message was sent using Webmail@INI: https://webmail.ini.ethz.ch
Reply | Threaded
Open this post in threaded view
|

Re: image capture

Gabriel Landini
On Monday 26 June 2006 18:37, Albert Cardona wrote:
> Yes you can have a plugin running on its own thread that never returns
> (never ends), and either use the Robot class to make clicks (your mouse
> pointer will move too, which is undesirable), or directly execute the
> button -just capture it by exploring down the Container classes.

Thanks, yes I am trying via the Robot class.

> For
> example, from the WindowManager get the window of the video, then lists its
> components, then for each one that is a container (JPanel, etc) list its
> components, et cetera until you find the button. Then "doClick()" on the
> button (if it's a JButton). It all may be easier by creating a MouseEvent
> with the button as the object and passing it to whatever object is the
> MouseListener (this is what java does internally anyway).

I will have a look at this. I think that the image capture plugin is just a
wrapper of their image capture which I guess it is written in C or C++ (it
looks the same, although some functions are greyed out), so that may not
work.
Anyway, I will post the robot when it is finished because I think it could be
quite handy.

Thanks again,

Gabriel