Class: OperaWatir::Keys
Instance Attribute Summary collapse
-
#browser ⇒ Object
Returns the value of attribute browser.
Instance Method Summary collapse
-
#down(*args) ⇒ Object
Holds down supplied arbitrary list of keys indefinitely.
-
#initialize(browser) ⇒ Keys
constructor
A new instance of Keys.
-
#release ⇒ Object
Releases all pressed down keys.
-
#send(*list) ⇒ Object
Presses an arbitrary list of keys or key combinations.
-
#up(*args) ⇒ Object
Depresses supplied arbitrary list of keys.
Constructor Details
#initialize(browser) ⇒ Keys
Returns a new instance of Keys.
6 7 8 |
# File 'lib/operawatir/keys.rb', line 6 def initialize(browser) self.browser = browser end |
Instance Attribute Details
#browser ⇒ Object
Returns the value of attribute browser.
4 5 6 |
# File 'lib/operawatir/keys.rb', line 4 def browser @browser end |
Instance Method Details
#down(*args) ⇒ Object
Holds down supplied arbitrary list of keys indefinitely.
26 27 28 |
# File 'lib/operawatir/keys.rb', line 26 def down(*args) args.each { |key| driver.keyDown(key) } end |
#release ⇒ Object
Releases all pressed down keys.
54 55 56 |
# File 'lib/operawatir/keys.rb', line 54 def release driver.releaseKeys end |
#send(*list) ⇒ Object
Presses an arbitrary list of keys or key combinations. Provided arguments are performed in sequence.
Symbols are parsed as modification keys (such as :control, :shift, :backspace, &c.), arraysd are interpreted as key combinations (e.g. [:control, ‘a’] will perform the combination C-a), and strings will be typed as regular words.
Note that this method is not OS indepdendent in the sense that even though OS X does not have Control keys, it will not replace your sent keys with Command.
Available modification keys: control, shift, access …TODO
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/operawatir/keys.rb', line 86 def send(*list) # TODO rename? list.each do |item| case item when Array item.each_with_index do |key, index| case key when :access access_key item[index + 1] when Symbol down key else key key end end release when Symbol key item else type item end end end |
#up(*args) ⇒ Object
Depresses supplied arbitrary list of keys.
42 43 44 |
# File 'lib/operawatir/keys.rb', line 42 def up(*args) args.each { |key| driver.keyUp(key) } end |