lib/mac-robot.rb in mac-robot-0.2.0 vs lib/mac-robot.rb in mac-robot-0.2.1

- old
+ new

@@ -1,10 +1,13 @@ require 'event_dispatcher' require 'util' module Mac class Robot + class Error < StandardError; end + class OutOfResolution < Error; end + attr_reader :x, :y BUTTONS = { :left => 0, :right => 1, @@ -42,11 +45,18 @@ def key_release(keycode) keyboard_event(keycode, 0) end 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 + + def display_pixel_size + @screen ||= Struct.new(:width, :height).new(*Util.get_display_pixel_size) end private def mouse_event(button, type)