Class: Mac::Robot
- Inherits:
-
Object
show all
- Defined in:
- lib/mac-robot.rb
Defined Under Namespace
Classes: Error, OutOfResolution
Constant Summary
collapse
- BUTTONS =
{
:left => 0,
:right => 1,
:center => 2
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Robot
Returns a new instance of Robot.
17
18
19
20
21
22
|
# File 'lib/mac-robot.rb', line 17
def initialize
@x = 0
@y = 0
@state = :mouse_up
@dispatcher = EventDispatcher.new
end
|
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
9
10
11
|
# File 'lib/mac-robot.rb', line 9
def x
@x
end
|
#y ⇒ Object
Returns the value of attribute y.
9
10
11
|
# File 'lib/mac-robot.rb', line 9
def y
@y
end
|
Instance Method Details
#display_pixel_size ⇒ Object
57
58
59
|
# File 'lib/mac-robot.rb', line 57
def display_pixel_size
@screen ||= Struct.new(:width, :height).new(*Util.get_display_pixel_size)
end
|
#get_pixel_color(x, y) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/mac-robot.rb', line 49
def get_pixel_color(x, y)
raise OutOfResolution if x < 0 || y < 0
raise OutOfResolution if display_pixel_size.width < x || display_pixel_size.height < y
color = Util.get_pixel_color(x, y)
Struct.new(:red, :green, :blue, :alpha).new(*color)
end
|
#key_press(keycode) ⇒ Object
41
42
43
|
# File 'lib/mac-robot.rb', line 41
def key_press(keycode)
keyboard_event(keycode, 1)
end
|
#key_release(keycode) ⇒ Object
45
46
47
|
# File 'lib/mac-robot.rb', line 45
def key_release(keycode)
keyboard_event(keycode, 0)
end
|
#mouse_move(x, y) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/mac-robot.rb', line 34
def mouse_move(x, y)
@x = x
@y = y
mouse_event(:left, :mouse_move)
end
|
#mouse_press(button = :left) ⇒ Object
24
25
26
27
|
# File 'lib/mac-robot.rb', line 24
def mouse_press(button = :left)
mouse_event(button, :mouse_down)
@state = :mouse_down
end
|
#mouse_release(button = :left) ⇒ Object
29
30
31
32
|
# File 'lib/mac-robot.rb', line 29
def mouse_release(button = :left)
mouse_event(button, :mouse_up)
@state = :mouse_up
end
|