Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/sikuli/clickable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions lib/sikuli/key_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ module Sikuli
# Alt Key
KEY_ALT = KeyModifier::ALT

# ESC Key
KEY_ESC = Key::ESC

# Backspace Key
KEY_BACKSPACE = Key::BACKSPACE

Expand Down
2 changes: 1 addition & 1 deletion lib/sikuli/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 27 additions & 0 deletions lib/sikuli/screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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