lib/rautomation/adapter/win_ffi/window.rb in rautomation-0.5.1 vs lib/rautomation/adapter/win_ffi/window.rb in rautomation-0.6.0
- old
+ new
@@ -2,11 +2,14 @@
module Adapter
module WinFfi
class Window
include WaitHelper
include Locators
+ extend ElementCollections
+ has_many :controls
+
class << self
def initialize_com
@@oleacc_module_handle = Functions.load_library "oleacc.dll"
Functions.co_initialize nil
end
@@ -107,23 +110,32 @@
sleep 1
end
# Activates the window and sends keys to it.
#
- # Refer to MSDN documentation at http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx
- # for the keycodes.
+ # Refer to KeystrokeConverter#convert_special_characters for the special keycodes.
# @see RAutomation::Window#send_keys
- def send_keys(*keys)
- keys.each do |key|
+ def send_keys(keys)
+ shift_pressed = false
+ KeystrokeConverter.convert(keys).each do |key|
wait_until do
activate
active?
end
- Functions.send_key(0x12, 0, 0, nil)
- Functions.send_key(key, 0, 0, nil)
- Functions.send_key(0x12, 0, Constants::KEYEVENTF_KEYUP, nil)
- Functions.send_key(key, 0, Constants::KEYEVENTF_KEYUP, nil)
+ press_key key
+
+ if key == Constants::VK_LSHIFT
+ shift_pressed = true
+ next
+ end
+
+ release_key key
+
+ if shift_pressed
+ shift_pressed = false
+ release_key Constants::VK_LSHIFT
+ end
end
end
# @see RAutomation::Window#close
def close
@@ -140,10 +152,26 @@
# @see RAutomation::Window#text_field
def text_field(locator)
TextField.new(self, locator)
end
+ def label(locator)
+ Label.new(self, locator)
+ end
+
+ def control(locator)
+ Control.new(self, locator)
+ end
+
+ def controls(locator)
+ Controls.new(self, locator)
+ end
+
+ def list_box(locator)
+ ListBox.new(self, locator)
+ end
+
# Redirects all method calls not part of the public API to the {Functions} directly.
# @see RAutomation::Window#method_missing
def method_missing(name, *args)
Functions.respond_to?(name) ? Functions.send(name, *args) : super
end
@@ -180,9 +208,20 @@
def child(locators)
RAutomation::Window.new Functions.child_window_locators(hwnd, locators)
end
end
+ private
+
+ def press_key key
+ Functions.send_key(key, 0, 0, nil)
+ sleep 0.01
+ end
+
+ def release_key key
+ Functions.send_key(key, 0, Constants::KEYEVENTF_KEYUP, nil)
+ sleep 0.1
+ end
end
end
end
end