diff --git a/lib/sikuli/clickable.rb b/lib/sikuli/clickable.rb index 59aa1fe..ff4c2ce 100644 --- a/lib/sikuli/clickable.rb +++ b/lib/sikuli/clickable.rb @@ -24,6 +24,26 @@ def click(*args) end end + # Public: Performs a hover on an image match or point (x, y) + # + # args - String representing filename of image to find and hover + # args - Fixnum, Fixnum representing x and y coordinates within + # a Region (0,0) is the top left + # + # Examples + # + # region.hover('smile.png') + # region.hover(123, 432) + # + # Returns nothing + def hover(*args) + case args.length + when 1 then hover_image(args[0]) + when 2 then hover_point(args[0], args[1]) + else raise ArgumentError + end + end + # Public: Performs a double click on an image match or point (x, y) # # args - String representing filename of image to find and click @@ -206,5 +226,35 @@ def click_point(x, y, is_double = false) @java_obj.click(org.sikuli.script::Location.new(x, y).offset(x(), y()), 0) end end + + # Private: hovers on a matched Region based on an image based search + # + # filename - A String representation of the filename of the region to + # match against + # + # Returns nothing + # + # Throws Sikuli::FileNotFound if the file could not be found on the system + # Throws Sikuli::ImageNotMatched if no matches are found within the region + def hover_image(filename) + begin + @java_obj.hover(filename) + rescue NativeException => e + raise_exception e, filename + end + end + + # Private: hovers on a point relative to a Region's top left corner + # + # x - a Fixnum representing the x component of the point to hover + # y - a Fixnum representing the y component of the point to hover + # + # Returns nothing + # + # Throws Sikuli::FileNotFound if the file could not be found on the system + # Throws Sikuli::ImageNotMatched if no matches are found within the region + def hover_point(x, y) + @java_obj.hover(org.sikuli.script::Location.new(x, y).offset(x(), y())) + end end end diff --git a/lib/sikuli/key_code.rb b/lib/sikuli/key_code.rb index cfb4a4a..97cfe80 100644 --- a/lib/sikuli/key_code.rb +++ b/lib/sikuli/key_code.rb @@ -19,6 +19,9 @@ module Sikuli # Alt Key KEY_ALT = KeyModifier::ALT + # ESC Key + KEY_ESC = Key::ESC + # Backspace Key KEY_BACKSPACE = Key::BACKSPACE diff --git a/lib/sikuli/platform.rb b/lib/sikuli/platform.rb index 7e94bd1..7f24faa 100644 --- a/lib/sikuli/platform.rb +++ b/lib/sikuli/platform.rb @@ -11,7 +11,7 @@ class Platform def self.sikuli_script_path if OS_X - path = "/Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar" + path = "/Applications/SikuliX-IDE.app/Contents/sikuli-script.jar" else raise LoadError, no_sikuli_home_err_msg if ENV['SIKULI_HOME'].nil? path = "#{ENV['SIKULI_HOME']}/sikuli-script.jar" diff --git a/lib/sikuli/screen.rb b/lib/sikuli/screen.rb index aad988d..70cb0a9 100644 --- a/lib/sikuli/screen.rb +++ b/lib/sikuli/screen.rb @@ -16,5 +16,32 @@ class Screen < Region def initialize @java_obj = org.sikuli.script::Screen.new() end + + + def capture(*args) + @java_obj.capture(*args) + end + + def captureRawDigest(x,y,w,h) + img = capture(x,y,w,h) + #puts v.java_class.declared_instance_methods + buffer = img.getImage.getRaster.getDataBuffer + #puts 'number of banks',b.getNumBanks + data = Array.new + j=0 + while j < buffer.getNumBanks + data.push(buffer.getData(j)) + j+=1 + end + + Digest::MD5.hexdigest(data.join) + end + + def captureDigest(x,y,w,h) + digest = captureRawDigest(x,y,w,h) + + 'DIGEST:{x=%s,y=%s,w=%s,h=%s}[%s]'% [x,y,w,h,digest] + end end + end \ No newline at end of file