Class: OmniAI::Tools::Computer::MacDriver
Overview
A driver for interacting with a Mac. Be careful with using as it can perform actions on your computer!
Constant Summary
Constants inherited
from BaseDriver
BaseDriver::DEFAULT_DISPLAY_SCALE, BaseDriver::DEFAULT_MOUSE_BUTTON
Instance Attribute Summary
Attributes inherited from BaseDriver
#display_height, #display_number, #display_width
Instance Method Summary
collapse
Methods inherited from BaseDriver
#mouse_double_click, #mouse_drag, #mouse_triple_click, #wait
Constructor Details
#initialize(keyboard: MacOS.keyboard, mouse: MacOS.mouse, display: MacOS.display) ⇒ MacDriver
Returns a new instance of MacDriver.
8
9
10
11
12
13
14
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 8
def initialize(keyboard: MacOS.keyboard, mouse: MacOS.mouse, display: MacOS.display)
@keyboard = keyboard
@mouse = mouse
@display = display
super(display_width: display.wide, display_height: display.high, display_number: display.id)
end
|
Instance Method Details
#hold_key(text:, duration:) ⇒ Object
23
24
25
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 23
def hold_key(text:, duration:)
raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end
|
#key(text:) ⇒ Object
17
18
19
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 17
def key(text:)
@keyboard.keys(text)
end
|
#mouse_click(coordinate:, button:) ⇒ Object
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 48
def mouse_click(coordinate:, button:)
x = coordinate[:x]
y = coordinate[:y]
case button
when "left" then @mouse.left_click(x:, y:)
when "middle" then @mouse.middle_click(x:, y:)
when "right" then @mouse.right_click(x:, y:)
end
end
|
#mouse_down(coordinate:, button: DEFAULT_MOUSE_BUTTON) ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 60
def mouse_down(coordinate:, button: DEFAULT_MOUSE_BUTTON)
x = coordinate[:x]
y = coordinate[:y]
case button
when "left" then @mouse.left_down(x:, y:)
when "middle" then @mouse.middle_down(x:, y:)
when "right" then @mouse.right_down(x:, y:)
end
end
|
#mouse_move(coordinate:) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 39
def mouse_move(coordinate:)
x = coordinate[:x]
y = coordinate[:y]
@mouse.move(x:, y:)
end
|
#mouse_position ⇒ Hash<{ x: Integer, y: Integer }>
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 28
def mouse_position
position = @mouse.position
x = position.x
y = position.y
{
x:,
y:,
}
end
|
#mouse_up(coordinate:, button: DEFAULT_MOUSE_BUTTON) ⇒ Object
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 73
def mouse_up(coordinate:, button: DEFAULT_MOUSE_BUTTON)
x = coordinate[:x]
y = coordinate[:y]
case button
when "left" then @mouse.left_up(x:, y:)
when "middle" then @mouse.middle_up(x:, y:)
when "right" then @mouse.right_up(x:, y:)
end
end
|
#screenshot {|file| ... } ⇒ Object
97
98
99
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 97
def screenshot(&)
@display.screenshot(&)
end
|
91
92
93
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 91
def scroll(amount:, direction:)
raise NotImplementedError, "#{self.class.name}##{__method__} undefined"
end
|
#type(text:) ⇒ Object
85
86
87
|
# File 'lib/omniai/tools/computer/mac_driver.rb', line 85
def type(text:)
@keyboard.type(text)
end
|