Method: Roi#press_key_until_displayed?
- Defined in:
- lib/roi/roi.rb
#press_key_until_displayed?(key, args = {}) ⇒ Boolean
Public: Presses a key until the given Roi is displayed.
Corresponds to api_press_key_till_<ROI TYPE>_displayed?
key - String name of key to press. presses - Integer maximum number of times to press the key (default: nil). timeout - Integer total milliseconds to allow before timing out (default: 30000). delay - Integer total milliseconds to delay before starting evaluation (default: 0). scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false).
Applies to image ROIs only.
try_every - Integer total milliseconds to delay between key presses (default: 3000). try_timeout - Integer total milliseconds to allow after each key press before timing out (default: nil). verifies_for - Integer total milliseconds for which the ROI must verify in order to succeed (default: 0).
If default, the ROI must only verify once.
priority - Symbol representing evaluation priority used to throttle CPU usage (default: :normal):
:critical - Sleep 10 milliseconds between intensive tasks (should be used sparingly).
:high - Sleep 100 milliseconds between intensive tasks.
:normal - Sleep 1 second between intensive tasks (default).
:low - Sleep 10 seconds between intensive tasks.
:background - Sleep 1 minute between intensive tasks (should be used sparingly).
log_every - Integer interval in milliseconds between logs (default: 1000). message - String message to log instead of the default (default: nil).
Default logs a tailored .
Returns Boolean true if displayed before the timeout, otherwise false.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/roi/roi.rb', line 142 def press_key_until_displayed?(key, args={}) logger.info("Pressing key #{key.inspect} until #{self.class.name} is displayed") timeout_s = args.fetch(:timeout, 30.sec) / 1.sec args[:timeout] = args[:try_timeout] key_delay = args.fetch(:try_every, 3.sec) presses = args[:presses] press_count = 0 start_time = Time.now displayed = false loop do displayed = displayed?(args) break if displayed if presses.nil? break if (Time.now - start_time) > timeout_s elsif press_count == presses break end @dut.press_key(key, :sleep_time => key_delay) press_count += 1 end displayed end |