class Samscript::Screen
Constants
- DefaultParams
Public Class Methods
capture(area = resolution)
click to toggle source
# File lib/samscript/screen.rb, line 17 def self.capture area = resolution rect = Rectangle.new area @robot ||= Robot.new @robot.create_screen_capture rect end
resolution()
click to toggle source
# File lib/samscript/screen.rb, line 12 def self.resolution @tk ||= Java::JavaAwt::Toolkit.get_default_toolkit @tk.get_screen_size end
wait_for_pixel(params = {}) { |true| ... }
click to toggle source
# File lib/samscript/screen.rb, line 23 def self.wait_for_pixel params = {} %w(location colour).map(&:to_sym).each do |sym| raise "invalid params" if params[sym].nil? end x, y = params[:location][0], params[:location][1] colour = params[:colour] tolerance = params[:tolerance] || DefaultParams[:tolerance] match = params[:match] || DefaultParams[:match] interval = params[:interval] || DefaultParams[:interval] timeout = params[:timeout] || DefaultParams[:timeout] attempts = (timeout/interval+1).floor return if match == :any or tolerance >= 255 attempts.times do screen = self.capture pixel = Samscript::Image.get_pixel(screen, x: x, y: y) if Samscript::Image.get_difference(pixel, colour) <= tolerance yield(true) if block_given? return end sleep(interval.to_f/1000) end yield(false) if block_given? end