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 or it’s area.

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 specified window’s top-left corner’s area

Win32::Screenshot::Take.of(:window, :title => /internet/i, :area => [10, 10, 20, 20])

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 an :area and/or :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):

  • :context (String, Symbol)

    Context to take a screenshot of. Can be :window or :client. Defaults to :window

  • :title (String, Regexp)

    Title of the window

  • :text (String, Regexp)

    Visible text of the window

  • :class (String, Regexp)

    Internal class name 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:



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

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, {:context => :window}.merge(opts))
end