Class: Win32::Screenshot::Take

Inherits:
Object
  • Object
show all
Defined in:
lib/win32/screenshot/take.rb

Overview

Capture Screenshots on Windows with Ruby

Class Method Summary collapse

Class Method Details

.of(what, opts = {}) ⇒ Image Also known as: new

Takes a screenshot of the specified object.

Examples:

Take a screenshot of the window with the specified title

Win32::Screenshot::Take.of(:window, :title => "Windows Internet Explorer")

Take a screenshot of the foreground

Win32::Screenshot::Take.of(:foreground)

Take a screenshot of the desktop

Win32::Screenshot::Take.of(:desktop)

Take a screenshot of the window with the specified handle

Win32::Screenshot::Take.of(:window, :hwnd => 123456)

Take a screenshot of the window’s client area (e.g. without title bar) with the specified handle

Win32::Screenshot::Take.of(:window, :hwnd => 123456, :context => :client)

Take a screenshot of the child window with the specified internal class name

Win32::Screenshot::Take.of(:rautomation, RAutomation::Window.new(:hwnd => 123456).child(:class => "Internet Explorer_Server"))

Parameters:

  • what (Symbol)

    the type of the object to take a screenshot of, possible values are :foreground, :desktop and :window.

  • opts (Hash) (defaults to: {})

    options are optional for specifying :context to take a screenshot. It is possible to specify as many options as are needed for searching for the unique window. By default the first window with matching identifiers will be taken screenshot of. It is possible to use in addition to other options a 0-based :index option to search for other windows if multiple windows match the specified criteria.

Options Hash (opts):

  • :title (String, Regexp)

    Title of the window

  • :text (String, Regexp)

    Visible text of the window

  • :hwnd (String, Fixnum)

    Window handle in decimal format

  • :pid (String, Fixnum)

    Window process ID (PID)

  • :index (String, Fixnum)

    0-based index to specify n-th window to take a screenshot of if all other criteria match

  • :rautomation (RAutomation::Window)

    RAutomation::Window object to take a screenshot of. Useful for taking screenshots of the child windows

Returns:



43
44
45
46
47
48
# File 'lib/win32/screenshot/take.rb', line 43

def of(what, opts = {})
  valid_whats = [:foreground, :desktop, :window]
  raise "It is not possible to take a screenshot of '#{what}', possible values are #{valid_whats.join(", ")}" unless valid_whats.include?(what)

  self.send(what, opts)
end