Class: OmniAI::Tools::Computer::BaseDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/omniai/tools/computer/base_driver.rb

Overview

A tool for interacting with a computer. Be careful with using as it can perform actions on your computer!

Examples:

class SomeDriver < BaseDriver
  @param text [String]
  def key(text:)
    # TODO
  end

  # @param text [String]
  # @param duration [Integer]
  def hold_key(text:, duration:)
    # TODO
  end

  # @return [Hash<{ x: Integer, y: Integer }>]
  def mouse_position
    # TODO
  end

  # @param coordinate [Hash<{ x: Integer, y: Integer }>]
  # @param button [String] e.g. "left", "middle", "right"
  def mouse_move(coordinate:)
    # TODO
  end

  # @param coordinate [Hash<{ x: Integer, y: Integer }>]
  # @param button [String] e.g. "left", "middle", "right"
  def mouse_click(coordinate:, button:)
    # TODO
  end

  # @param coordinate [Hash<{ x: Integer, y: Integer }>]
  # @param button [String] e.g. "left", "middle", "right"
  def mouse_down(coordinate:, button:)
    # TODO
  end

  # @param coordinate [Hash<{ x: Integer, y: Integer }>]
  # @param button [String] e.g. "left", "middle", "right"
  def mouse_up(coordinate:, button:)
    # TODO
  end

  # @param text [String]
  def type(text:)
    # TODO
  end

  # @param amount [Integer]
  # @param direction [String] e.g. "up", "down", "left", "right"
  def scroll(amount:, direction:)
    # TODO
  end

  # @yield [file]
  # @yieldparam file [File]
  def screenshot
    # TODO
  end
end

Direct Known Subclasses

MacDriver

Constant Summary collapse

DEFAULT_MOUSE_BUTTON =
"left"
DEFAULT_DISPLAY_SCALE =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(display_width:, display_height:, display_number:) ⇒ BaseDriver

Returns a new instance of BaseDriver.

Parameters:

  • display_width (Integer)

    the width of the display in pixels

  • display_height (Integer)

    the height of the display in pixels

  • display_number (Integer)

    the display number



86
87
88
89
90
91
# File 'lib/omniai/tools/computer/base_driver.rb', line 86

def initialize(display_width:, display_height:, display_number:)
  @display_width = display_width
  @display_height = display_height

  @display_number = display_number
end

Instance Attribute Details

#display_heightObject

Returns the value of attribute display_height.



77
78
79
# File 'lib/omniai/tools/computer/base_driver.rb', line 77

def display_height
  @display_height
end

#display_numberObject

Returns the value of attribute display_number.



81
82
83
# File 'lib/omniai/tools/computer/base_driver.rb', line 81

def display_number
  @display_number
end

#display_widthObject

Returns the value of attribute display_width.



73
74
75
# File 'lib/omniai/tools/computer/base_driver.rb', line 73

def display_width
  @display_width
end

Instance Method Details

#hold_key(text:, duration:) ⇒ Object

Parameters:

  • text (String)
  • duration (Integer)

Raises:

  • (NotImplementedError)


100
101
102
# File 'lib/omniai/tools/computer/base_driver.rb', line 100

def hold_key(text:, duration:)
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#key(text:) ⇒ Object

Parameters:

  • text (String)

Raises:

  • (NotImplementedError)


94
95
96
# File 'lib/omniai/tools/computer/base_driver.rb', line 94

def key(text:)
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#mouse_click(coordinate:, button:) ⇒ Object

Parameters:

  • coordinate (Hash<{ x: Integer, y: Integer }>)
  • button (String)

    e.g. “left”, “middle”, “right”

Raises:

  • (NotImplementedError)


117
118
119
# File 'lib/omniai/tools/computer/base_driver.rb', line 117

def mouse_click(coordinate:, button:)
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#mouse_double_click(coordinate:, button:) ⇒ Object

Parameters:

  • coordinate (Hash<{ x: Integer, y: Integer }>)
  • button (String)

    e.g. “left”, “middle”, “right”



143
144
145
# File 'lib/omniai/tools/computer/base_driver.rb', line 143

def mouse_double_click(coordinate:, button:)
  2.times { mouse_click(coordinate:, button:) }
end

#mouse_down(coordinate:, button:) ⇒ Object

Parameters:

  • coordinate (Hash<{ x: Integer, y: Integer }>)
  • button (String)

    e.g. “left”, “middle”, “right”

Raises:

  • (NotImplementedError)


123
124
125
# File 'lib/omniai/tools/computer/base_driver.rb', line 123

def mouse_down(coordinate:, button:)
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#mouse_drag(coordinate:, button: DEFAULT_MOUSE_BUTTON) ⇒ Object

Parameters:

  • coordinate (Hash<{ x: Integer, y: Integer }>)
  • button (String) (defaults to: DEFAULT_MOUSE_BUTTON)

    e.g. “left”, “middle”, “right”



135
136
137
138
139
# File 'lib/omniai/tools/computer/base_driver.rb', line 135

def mouse_drag(coordinate:, button: DEFAULT_MOUSE_BUTTON)
  mouse_down(coordinate: mouse_position, button:)
  mouse_move(coordinate:, button:)
  mouse_up(coordinate:, button:)
end

#mouse_move(coordinate:) ⇒ Object

Parameters:

  • coordinate (Hash<{ x: Integer, y: Integer }>)
  • button (String)

    e.g. “left”, “middle”, “right”

Raises:

  • (NotImplementedError)


111
112
113
# File 'lib/omniai/tools/computer/base_driver.rb', line 111

def mouse_move(coordinate:)
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#mouse_positionHash<{ x: Integer, y: Integer }>

Returns:

  • (Hash<{ x: Integer, y: Integer }>)

Raises:

  • (NotImplementedError)


105
106
107
# File 'lib/omniai/tools/computer/base_driver.rb', line 105

def mouse_position
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#mouse_triple_click(coordinate:, button:) ⇒ Object

Parameters:

  • coordinate (Hash<{ x: Integer, y: Integer }>)
  • button (String)

    e.g. “left”, “middle”, “right”



149
150
151
# File 'lib/omniai/tools/computer/base_driver.rb', line 149

def mouse_triple_click(coordinate:, button:)
  3.times { mouse_click(coordinate:, button:) }
end

#mouse_up(coordinate:, button:) ⇒ Object

Parameters:

  • coordinate (Hash<{ x: Integer, y: Integer }>)
  • button (String)

    e.g. “left”, “middle”, “right”

Raises:

  • (NotImplementedError)


129
130
131
# File 'lib/omniai/tools/computer/base_driver.rb', line 129

def mouse_up(coordinate:, button:)
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#screenshot {|file| ... } ⇒ Object

Yields:

  • (file)

Yield Parameters:

  • file (File)

Raises:

  • (NotImplementedError)


166
167
168
# File 'lib/omniai/tools/computer/base_driver.rb', line 166

def screenshot
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#scroll(amount:, direction:) ⇒ Object

Parameters:

  • amount (Integer)
  • direction (String)

    e.g. “up”, “down”, “left”, “right”

Raises:

  • (NotImplementedError)


160
161
162
# File 'lib/omniai/tools/computer/base_driver.rb', line 160

def scroll(amount:, direction:)
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#type(text:) ⇒ Object

Parameters:

  • text (String)

Raises:

  • (NotImplementedError)


154
155
156
# File 'lib/omniai/tools/computer/base_driver.rb', line 154

def type(text:)
  raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end

#wait(duration:) ⇒ Object

Parameters:

  • duration (Integer)


171
172
173
# File 'lib/omniai/tools/computer/base_driver.rb', line 171

def wait(duration:)
  Kernel.sleep(duration)
end