class RAutomation::Adapter::Win32::Keys

Constants

KEYS
MAPPED_KEYS
SPECIAL_KEYS

Assumes US standard keyboard layout

Public Class Methods

[](key) click to toggle source
# File lib/rautomation/adapter/win_32/keys.rb, line 118
def self.[](key)
  KEYS[key] or raise "unsupported key #{key.inspect}"
end
encode(keys) click to toggle source
# File lib/rautomation/adapter/win_32/keys.rb, line 122
def self.encode(keys)
  keys.reduce([]) do |converted, key|
    if key.is_a?(Symbol)
      converted << Keys[key]
    elsif key.is_a?(Array)
      converted << (key.map {|k| encode([k])} << Keys[:null]).flatten
    else # key is a string
      converted += encode_str(key)
    end
    converted
  end
end
encode_str(keys) click to toggle source
# File lib/rautomation/adapter/win_32/keys.rb, line 135
def self.encode_str(keys)
  keys.to_s.split("").map do |key|
    key =~ /[a-z]/ || MAPPED_KEYS[key] ? MAPPED_KEYS[key] || key.upcase.unpack("c")[0] : 
      key =~ /[A-Z]/ || SPECIAL_KEYS[key] ? [Keys[:shift], SPECIAL_KEYS[key] || key.unpack("c")[0], Keys[:null]] :
      key.unpack("c")[0]
  end
end