Results 1 to 9 of 9
- 10-05-2013, 03:31 AM #1
Member
- Join Date
- Oct 2013
- Posts
- 9
- Rep Power
- 0
Using Robot to automize actions in non-java applications
Hello,
I've recently been trying to utilize the java.awt.Robot to automize certain mouse/keyboard functions without using the actual mouse. I basically plan to use a fake mouse object like here:
Java Code:MouseAdapter mouseImpl = new MouseAdapter() { private Component lastPressed; @Override public void mousePressed(MouseEvent e) { redirectMouseEvent(e); } @Override public void mouseReleased(MouseEvent e) { redirectMouseEvent(e); } @Override public void mouseClicked(MouseEvent e) { redirectMouseEvent(e); } @Override public void mouseMoved(MouseEvent e) { redirectMouseEvent(e); } @Override public void mouseDragged(MouseEvent e) { redirectMouseEvent(e); } private void redirectMouseEvent(MouseEvent e) { Component redirectTo = SwingUtilities.getDeepestComponentAt(panel, e.getX(), e.getY()); if (e.getID() == MouseEvent.MOUSE_PRESSED) { lastPressed = redirectTo; } else if (e.getID() == MouseEvent.MOUSE_DRAGGED || e.getID() == MouseEvent.MOUSE_RELEASED) { redirectTo = lastPressed; } if (redirectTo != null) { lastMouseX = e.getX(); lastMouseY = e.getY(); panel.repaint(); //this line is just to update the glass pane e = SwingUtilities.convertMouseEvent(panel, e, redirectTo); java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e); } } }; remoteFrame.getContentPane().addMouseListener(mouseImpl); remoteFrame.getContentPane().addMouseMotionListener(mouseImpl);
However the program I'm trying to do this in isn't in any way java related. My question is, can I still use a fake mouse on this program (perhaps if I can open the program inside my own client) or is this impossible. (if so.. any suggestions?)
Thanks in advance,
Jeroen V.
- 10-05-2013, 08:42 AM #2
Re: Using Robot to automize actions in non-java applications
Yes, you can. I once wrote a small Java program to "press" a series of keys at set intervals to twist chants for my brother's paladin in Dark Age of Camelot.
Get in the habit of using standard Java naming conventions!
- 10-05-2013, 08:48 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: Using Robot to automize actions in non-java applications
It can't be done; an indication is in your own redirectMouseEvent( ... ) method: it needs a target Component in the same JVM; if the other application isn't even a Java application there are no Components ...
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 10-05-2013, 09:08 AM #4
Re: Using Robot to automize actions in non-java applications
Hm... well, maybe not like that. But you can use Robot#mouseMove(...), #mousePress(...), etc. as well as #keyPress(...), etc. to interact with non-Java programs.
Get in the habit of using standard Java naming conventions!
- 10-05-2013, 10:16 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 10-05-2013, 12:47 PM #6
Re: Using Robot to automize actions in non-java applications
You can use Robot to first take a screenshot, analyze that image to locate a known graphic, then you can compute the correct coordinates for the Robot to initiate mouse interactions.
I once wrote a Windows Minesweeper solver which located the smiley face on the reset button for reference coordinates (It could solve the Advanced level in one or two seconds). And then Microsoft totally changed the Minesweeper UI in Vista and my program became useless
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 10-05-2013, 02:49 PM #7
Member
- Join Date
- Oct 2013
- Posts
- 9
- Rep Power
- 0
Re: Using Robot to automize actions in non-java applications
So, you're saying that it's impossible to run a non-java program inside my client to read its output. As another question, is it possible to fake mouse/keyboard that certain program when it's minimized?
- 10-05-2013, 03:23 PM #8
- 10-05-2013, 03:38 PM #9
Member
- Join Date
- Oct 2013
- Posts
- 9
- Rep Power
- 0
Re: Using Robot to automize actions in non-java applications
Well, with that I mean that the program would create a mouse/keyboard object inside that program that does certain operations while I could continue doing other things with my own mouse.
For example, I would have a bot that goes through my mail using a fake mouse while I'm checking these forums with the real mouse. The catch here is that I would want the bot to keep going through the mail even though I minized the mail program. So I can't just let the fake mouse use normal screen coordinates, I would need to input and output coordinates in the mail viewing program. Which is why I think I would need to open the program inside my botclient, so my botclient can keep track of those coordinates.Last edited by JeroenV; 10-05-2013 at 03:44 PM.
Similar Threads
-
My Java Robot Obstacle drawing
By Naphoria in forum New To JavaReplies: 5Last Post: 01-19-2012, 05:59 PM -
Java Robot: Getting the X, Y location of a pixel with a certain color. Impossible?
By JeffThomas in forum Advanced JavaReplies: 3Last Post: 12-03-2011, 02:38 PM -
Taking screenshot using java robot class not woring when pc is locked.
By sagngh8 in forum New To JavaReplies: 2Last Post: 05-22-2011, 09:56 AM -
Help with Java Robot and Runtime Class
By Rmond1254 in forum New To JavaReplies: 1Last Post: 02-18-2009, 07:33 AM -
Java Robot commands not working
By CoolLove in forum Java AppletsReplies: 2Last Post: 01-13-2009, 03:58 PM
Bookmarks