views:

105

answers:

3

In what language can I write a quick program to take screenshots and also possibly emulate a keypress?

I have an animated/interactive flash movie that is a presentation. I want to take a screenshot after I press a particular key.

The end effect is a bunch of screenshots that I can print...basically captures the key moments in the flash presentation.

+3  A: 

I've written this in C# without much hassle. Here's the bulk of the code:

    using (Bitmap bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height, PixelFormat.Format24bppRgb))
    using (Graphics graphics = Graphics.FromImage(bitmap))
    {
        graphics.CopyFromScreen(
            new Point(0, 0), 
            new Point(0, 0), 
            bitmapSize);
        bitmap.Save(filename, ImageFormat.Png);
    }

I would recommend writing an app that hosts a browser control. Then you could have the browser control show the SWF and your app would know the exact coordinates of the part of the screen you need to capture. That way you can avoid having to capture a whole screen or whole window that you may have to crop later.

Gabe
This is cool. I've never done C#...maybe it's time to try it! :)
milesmeow
+1  A: 

i am sure there are ways, but here's my idea. you can convert your movie frames to pictures using tools like ffmpeg . From the man page of ffmpeg

ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo-%03d.jpeg

This will extract one video frame per second from the video and will output them in files named foo-001.jpeg, foo-002.jpeg, etc. Images will be rescaled to fit the new WxH values.

If you want to extract just a limited number of frames, you can use the above command in combination with the -vframes or -t option, or in combination with -ss to start extracting from a certain point in time.

The number in the file name "simulates" the key press, so if you extracted for 1 sec per frame, and you want to "press" the key at 30sec, use the file name with foo-030.jpeg

ghostdog74
This is a great solution if I have a video and want to take frames. I'll keep this in mind if I ever want to do this.
milesmeow
your flash movie is also a "video".
ghostdog74
Are we talking about .flv's or .swf's? I have a .swf that is interactive.
milesmeow
A: 

There's a free tool that I found about recently that does the screen capture part, It's apparently written in java.

http://screenr.com/

John Knoeller