Class: OmniAI::Tools::ComputerTool
- Inherits:
-
OmniAI::Tool
- Object
- OmniAI::Tool
- OmniAI::Tools::ComputerTool
- Defined in:
- lib/omniai/tools/computer_tool.rb
Overview
A tool for interacting with a computer. Be careful with using as it can perform actions on your computer!
Defined Under Namespace
Modules: Action, MouseButton, ScrollDirection
Constant Summary collapse
- ACTIONS =
[ Action::KEY, Action::HOLD_KEY, Action::MOUSE_POSITION, Action::MOUSE_MOVE, Action::MOUSE_CLICK, Action::MOUSE_DOWN, Action::MOUSE_DRAG, Action::MOUSE_UP, Action::TYPE, Action::SCROLL, Action::WAIT, ].freeze
- MOUSE_BUTTON_OPTIONS =
[ MouseButton::LEFT, MouseButton::MIDDLE, MouseButton::RIGHT, ].freeze
- SCROLL_DIRECTION_OPTIONS =
[ ScrollDirection::UP, ScrollDirection::DOWN, ScrollDirection::LEFT, ScrollDirection::RIGHT, ].freeze
Instance Method Summary collapse
- #execute(action:, coordinate: nil, text: nil, duration: nil, mouse_button: nil, scroll_direction: nil, scroll_amount: nil) ⇒ Object
-
#initialize(driver:, logger: Logger.new(IO::NULL)) ⇒ ComputerTool
constructor
A new instance of ComputerTool.
Constructor Details
#initialize(driver:, logger: Logger.new(IO::NULL)) ⇒ ComputerTool
Returns a new instance of ComputerTool.
139 140 141 142 143 |
# File 'lib/omniai/tools/computer_tool.rb', line 139 def initialize(driver:, logger: Logger.new(IO::NULL)) @driver = driver @logger = logger super() end |
Instance Method Details
#execute(action:, coordinate: nil, text: nil, duration: nil, mouse_button: nil, scroll_direction: nil, scroll_amount: nil) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/omniai/tools/computer_tool.rb', line 152 def execute( action:, coordinate: nil, text: nil, duration: nil, mouse_button: nil, scroll_direction: nil, scroll_amount: nil ) @logger.info({ action:, coordinate:, text:, duration:, mouse_button:, scroll_direction:, scroll_amount:, }.compact.map { |key, value| "#{key}=#{value.inspect}" }.join(" ")) case action when Action::KEY then @driver.key(text:) when Action::HOLD_KEY then @driver.hold_key(text:, duration:) when Action::MOUSE_POSITION then @driver.mouse_position when Action::MOUSE_MOVE then @driver.mouse_move(coordinate:) when Action::MOUSE_CLICK then @driver.mouse_click(coordinate:, button: ) when Action::MOUSE_DOUBLE_CLICK then @driver.mouse_double_click(coordinate:, button: ) when Action::MOUSE_TRIPLE_CLICK then @driver.mouse_triple_click(coordinate:, button: ) when Action::MOUSE_DOWN then @driver.mouse_down(coordinate:, button: ) when Action::MOUSE_UP then @driver.mouse_up(coordinate:, button: ) when Action::MOUSE_DRAG then @driver.mouse_drag(coordinate:, button: ) when Action::TYPE then @driver.type(text:) when Action::SCROLL then @driver.scroll(amount: scroll_amount, direction: scroll_direction) when Action::WAIT then @driver.wait(duration:) end end |