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.
15
16
17
18
19
20
21
|
# File 'lib/mac-robot.rb', line 15
def initialize
@x = 0
@y = 0
@state = :mouse_up
@dispatcher = EventDispatcher.new
end
|
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
11
12
13
|
# File 'lib/mac-robot.rb', line 11
def x
@x
end
|
#y ⇒ Object
Returns the value of attribute y.
11
12
13
|
# File 'lib/mac-robot.rb', line 11
def y
@y
end
|
Instance Method Details
#display_pixel_size ⇒ Object
86
87
88
|
# File 'lib/mac-robot.rb', line 86
def display_pixel_size
@screen ||= Struct.new(:width, :height).new(*Util.get_display_pixel_size)
end
|
#get_pixel_color(x, y) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/mac-robot.rb', line 69
def get_pixel_color(x, y)
raise OutOfResolution if x < 0 || y < 0
if display_pixel_size.width < x || display_pixel_size.height < y
raise OutOfResolution
end
x = x - 0.1 if display_pixel_size.width == x
color = Util.get_pixel_color(x, y)
Struct.new(:red, :green, :blue, :alpha).new(*color)
end
|
#key_press(keycode) ⇒ Object
52
53
54
|
# File 'lib/mac-robot.rb', line 52
def key_press(keycode)
keyboard_event(keycode, 1)
end
|
#key_release(keycode) ⇒ Object
56
57
58
|
# File 'lib/mac-robot.rb', line 56
def key_release(keycode)
keyboard_event(keycode, 0)
end
|
#mouse_current_location ⇒ Object
47
48
49
50
|
# File 'lib/mac-robot.rb', line 47
def mouse_current_location
loc = Util.get_mouse_current_location
Struct.new(:x, :y).new(*loc)
end
|
#mouse_drag(x, y) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/mac-robot.rb', line 40
def mouse_drag(x, y)
@x = x
@y = y
mouse_event(:left, :mouse_drag)
end
|
#mouse_move(x, y) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/mac-robot.rb', line 33
def mouse_move(x, y)
@x = x
@y = y
mouse_event(:left, :mouse_move)
end
|
#mouse_press(button = :left) ⇒ Object
23
24
25
26
|
# File 'lib/mac-robot.rb', line 23
def mouse_press(button = :left)
mouse_event(button, :mouse_down)
@state = :mouse_down
end
|
#mouse_release(button = :left) ⇒ Object
28
29
30
31
|
# File 'lib/mac-robot.rb', line 28
def mouse_release(button = :left)
mouse_event(button, :mouse_up)
@state = :mouse_up
end
|
60
61
62
|
# File 'lib/mac-robot.rb', line 60
def scroll_wheel_line(args = {})
scroll_wheel_event(:line, *(args))
end
|
65
66
67
|
# File 'lib/mac-robot.rb', line 65
def scroll_wheel_pixel(args = {})
scroll_wheel_event(:pixel, *(args))
end
|