Sha256: fc63df60b029f13779c5656b8b4be5eabb1616993e798e48dc95cd86d403c5c7

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

#include "StdAfx.h"
#include "AutomationClicker.h"

bool AutomationClicker::Click() {
  try {
    if( CanInvoke() ) {
      Invoke();
    } else if( CanToggle() ) {
      Toggle();
    } else if( CanSelect() ) {
      Select();
    }

    return true;
  } catch(Exception^ e) {
    Console::WriteLine("AutomationClicker::Click - {0}", e->Message);
    return false;
  }

	throw gcnew Exception(gcnew String("AutomationElement did not support the InvokePattern, TogglePattern or the SelectionItemPattern"));
}

void AutomationClicker::MouseClick() {
	_control->SetFocus();
	auto clickablePoint = _control->GetClickablePoint();
	Cursor::Position = System::Drawing::Point((int)clickablePoint.X, (int)clickablePoint.Y);
	mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}

bool AutomationClicker::CanInvoke() {
	return (bool)(_control->GetCurrentPropertyValue(AutomationElement::IsInvokePatternAvailableProperty));
}

void AutomationClicker::Invoke() {
	dynamic_cast<InvokePattern^>(_control->GetCurrentPattern(InvokePattern::Pattern))->Invoke();
}

bool AutomationClicker::CanToggle() {
	return (bool)(_control->GetCurrentPropertyValue(AutomationElement::IsTogglePatternAvailableProperty));
}

void AutomationClicker::Toggle() {
	dynamic_cast<TogglePattern^>(_control->GetCurrentPattern(TogglePattern::Pattern))->Toggle();
}

bool AutomationClicker::CanSelect() {
	return (bool)(_control->GetCurrentPropertyValue(AutomationElement::IsSelectionItemPatternAvailableProperty));
}

void AutomationClicker::Select() {
	dynamic_cast<SelectionItemPattern^>(_control->GetCurrentPattern(SelectionItemPattern::Pattern))->Select();
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rautomation-0.10.0 ext/UiaDll/UiaDll/AutomationClicker.cpp
rautomation-0.9.4 ext/UiaDll/UiaDll/AutomationClicker.cpp
rautomation-0.9.3 ext/UiaDll/UiaDll/AutomationClicker.cpp
rautomation-0.9.2 ext/UiaDll/UiaDll/AutomationClicker.cpp