views:

267

answers:

2

Instead of using some third party app, I'd like to write an app in Ruby that when invoked, will capture the full screen and save it in c:\screenshot\snap000001.png

The graphic package is readily there, but how can you capture a region from the full screen so as to save it?

This program is to be invoked by some hot-key, such as setting it to be running when CTRL-PrtScn is pressed, or CTRL-CTRL (both control on left and right), or ALT-ALT.

+5  A: 

I haven't tried it (I'm not on windows). But you could use Win32::Screenshot.

While looking around, I've found the following, which does the screenshot using that library

width, height, bitmap = Win32::Screenshot.desktop
img_lst = ImageList.new
img_lst.from_blob(bitmap)
img_lst.write('public/screen.png')

And should write your screenshot as a png file.

Damien MATHIEU
A: 

If you need the non blocking getch see http://betterlogic.com/roger/?p=2930 for hints.

rogerdpack