Код: Выделить всё
string ApplicationName = "Form1";
string ButtonName = "Button1";
var windows = AutomationElement.RootElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));
MessageBox.Show(windows.ToString());
foreach (AutomationElement window in windows)
{
var windowName = window.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;
MessageBox.Show(windowName.ToString());
if (windowName.StartsWith(ApplicationName))
{
MessageBox.Show(windowName.StartsWith(ApplicationName).ToString());
var button = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, ButtonName));
System.Threading.Thread.Sleep(1000);
if (button != null)
{
var invokePattern = button.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
invokePattern.Invoke();
MessageBox.Show("ButtonPress");
return;
}
//else
//{
// Console.WriteLine("ButtonNotPress");
//}
}
}
MessageBox.Show("ButtonNotFound");
Но это не очень работает, например: Он нажмет на простую кнопку в моей форме, но не нажмет ни на одну кнопку в игре.
p>
Есть ли способы лучше этого, который гарантированно нажимает на кнопку, или придется шить изображение через OpenCV?.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ng-c-sharp
Мобильная версия