Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Can I scan the screen or get a screenshot of my screen within Java?  (Read 1773 times)
0 Members and 1 Guest are viewing this topic.
Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Posted 2006-10-18 17:57:33 »

I'm making a program to save certain keyboard or mouse actions you have done on your computer and reproduce them for you, helping out with a lot of things like mundane multimedia tasks and whatnot. I want you to be able to provide conditionals that will cause the program to produce certain actions, and these conditionals I want to rely solely on what is being displayed on your monitor.

Like, for example, I want the program to automatically log in to something for me once it opens, like JGO. It would need to scan the screen to see if it perhaps had the JGO banner in the expected place. If it did, it would automatically click in the login box, type out my name, then the password box and type out my password.

Yes, pretty ambitious, but I've got pretty much everything working already. I'm just wondering if there's some way to return what's being displayed as a BufferedImage, or to get a screenshot of it, at least, which may be a little processor intensive but it would certainly work.

Any ideas? Thanks guys.

See my work:
OTC Software
Offline woogley
« Reply #1 - Posted 2006-10-18 18:32:43 »

Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #2 - Posted 2006-10-18 18:48:23 »

Amazingly, I was already using Robot and didn't see that. Thanks very much.

Any idea how costly this operation is?

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline woogley
« Reply #3 - Posted 2006-10-18 19:13:50 »

try out this test:
import java.awt.*;
public class ScreenTest {
   public static void main(String args[]) {
      try {
         long now = System.currentTimeMillis();
         long ms = 0;
         Robot r = new Robot();
         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
         Rectangle rect = new Rectangle(0,0,d.width,d.height);
         int count = 0;
         while (ms < 5000) {
            now = System.currentTimeMillis();
         System.out.println(count+" screenshots taken in "+(ms/1000.0)+" seconds");
      catch (AWTException e) {

for me I get about 14 screen captures per second on a 1024x768 screen. if you already have a presumed position for, say, the JGO banner, you can just use a smaller Rectangle for the screen capture and it should be alot faster than taking an ENTIRE screenshot
Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #4 - Posted 2006-10-18 23:36:19 »

Ooh yeah, that's working really fast. I just have the user specify a certain rectangle that they want to search for, generally not larger than 50x50 pixels. 50x50 pixels goes really really fast. I can also put in the option to scan the screen for certain patterns, and therefore it would work across multiple resolutions, at least somewhat (look for the text box pattern, because it will always be the same size, etc.)

I wonder if there would be any way to get this to work flawlessly aside from forcing a resolution change. The windows will obviously move around and be in different places depending on resolution, even depending on computer. I suppose I could do something called findWindow() function that finds the window in question so it is only performed once to get a relative position, then smaller screen analysis can be performed. But can you think of another way to do this?

See my work:
OTC Software
Offline Abuse

JGO Knight

Medals: 28

falling into the abyss of reality

« Reply #5 - Posted 2006-10-19 00:16:53 »

Hook into the win32 api?!

Grabbing a screenshot and trying to derive what is where is a completely backward way of doing it.

You code is going to be platform specific anyway, so you might as well make use of the underlying api's provided to fulfill the exact feature you desire.

You never know, there may already be a java wrapper around for querying the active processes and/or window handles that are currently active.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here!
Offline woogley
« Reply #6 - Posted 2006-10-19 02:30:59 »

abuse is right, there are 100's of things that can get in the way with the screen capture method. the user can change the size of the titlebar text, which can throw everything off, for example..
Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #7 - Posted 2006-10-19 23:13:39 »

Yeah, this is wholly true, but even if I could contact Windows does that mean that I could have Internet Explorer return to me its window size, font size, locations of text fields, etc.? I feel like even if I could do that it would just because program specific. I want this to be functionable through any program as long as the user saves a set of actions depending on different highlights on their screen.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (27 views)
2015-08-04 11:03:17

SHC (44 views)
2015-08-01 03:58:20

Jesse (25 views)
2015-07-29 04:35:27

Riven (48 views)
2015-07-27 16:38:00

Riven (26 views)
2015-07-27 15:35:20

Riven (28 views)
2015-07-27 12:26:13

Riven (19 views)
2015-07-27 12:23:39

BurntPizza (42 views)
2015-07-25 00:14:37

BurntPizza (56 views)
2015-07-24 22:06:39

BurntPizza (35 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!