Class: OperaWatir::Keys

Inherits:
Object show all
Defined in:
lib/operawatir/keys.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#browserObject

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.

Examples:


browser.keys.down 'a'
browser.keys.down 'a', :right

Parameters:

  • *args (Symbol, String)

    Arbitrary list of symbols (modification) keys or strings (regular keys) to be pressed down.



26
27
28
# File 'lib/operawatir/keys.rb', line 26

def down(*args)
  args.each { |key| driver.keyDown(key) }
end

#releaseObject

Releases all pressed down keys.

Examples:

browser.keys.down :control, :shift, 'a'
browser.keys.release


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

Examples:

browser.keys.send 'a'
browser.keys.send 'foo', 'bar'
browser.keys.send :control
browser.keys.send [:control, 'a']
browser.keys.send [:control, 'a'], :backspace

Parameters:

  • *list (Symbol, Array, String)

    Arbitrary list of symbols, arrays or strings which will form a sequence of keys to be pressed.



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.

Examples:

browser.keys.up 'a', :right

Parameters:

  • *args (Symbol, String)

    Arbitrary list of symbols (modification keys) or strings (regular keys) to be depressed.



42
43
44
# File 'lib/operawatir/keys.rb', line 42

def up(*args)
  args.each { |key| driver.keyUp(key) }
end