How to capture a window screen shot in Ruby

Viewed 432

Whenever I want to capture a screenshot in my code I was using CTRL+PRTSCR, but it is not working. Is there anther way to capture a screenshot pragmatically in Ruby?

Here's is my code: require 'win32ole'

autoIt = WIN32OLE.new("AutoItX3.Control")
autoIt.Send("{CTRLDOWN}{PRINTSCREEN}{CRTLUP}")
1 Answers

Actually we have a library for screenshot in win32 we can make use of that library in order to solve this problem. Here is the piece of code that might help you

require 'win32/screenshot'
Win32::Screenshot::Take.of(:foreground).write("Screenshot.png")
Related