Exemplo n.º 1
0
 private static string EditInOut(AutomationElement ae, bool isOut, string key, string windowName)
 {
     if (isOut)
     {
         ValuePattern pattern;
         pattern = ae.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
         return(pattern.Current.Value);
     }
     else
     {
         ValuePattern pattern;
         pattern = ae.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
         Utility.wait(2);
         try {
             pattern.SetValue(key);
         } catch (InvalidOperationException) {
             ControlOp co = new ControlOp();
             co.SetForeground(windowName);
             Utility.wait(2);
             KeyboardOp.sendKey(key);
             Utility.wait(2);
             return("key sent");
         }
         return("No key sent");
     }
 }
Exemplo n.º 2
0
        public static string SelectItemByCount(string WindowName, string lID, int count)
        {
            int maxCount            = ItemCount(WindowName, lID);
            AutomationElement item1 = TreeWalker.ControlViewWalker.GetFirstChild(getListElement(WindowName, lID));

            if (count <= maxCount && count > 0)
            {
                if (count == 1)
                {
                    SelectionItemPattern pattern;
                    pattern = item1.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
                    pattern.Select();
                    try
                    {
                        System.Windows.Point p = item1.GetClickablePoint();
                        MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y));
                    }
                    catch (NoClickablePointException)
                    {
                        KeyboardOp.sendKey("{enter}");
                    }
                    return("Done");
                }
                else
                {
                    for (int index = 1; index < count; index++)
                    {
                        item1 = TreeWalker.ControlViewWalker.GetNextSibling(item1);
                    }
                    SelectionItemPattern pattern;
                    pattern = item1.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
                    pattern.Select();
                    try
                    {
                        System.Windows.Point p = item1.GetClickablePoint();
                        MouseClick.DoMouseClick(Convert.ToInt32(p.X), Convert.ToInt32(p.Y));
                    }
                    catch (NoClickablePointException)
                    {
                        KeyboardOp.sendKey("{enter}");
                    }
                    return("Done");
                }
            }
            return("Item not found");
        }
Exemplo n.º 3
0
        public static string CheckBoxToggle(string wName, string cName, bool isPartContainCheckedListItemName)
        {
            ControlOp     co   = new ControlOp(cName, ControlType.ListItem);
            List <IntPtr> hWnd = co.GetChildWindow(wName);

            if (hWnd.Count != 0)
            {
                for (int i = hWnd.Count - 1; i >= 0; i--)
                {
                    AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(hWnd[i]));
                    foreach (AutomationElement ae in aec)
                    {
                        if (isPartContainCheckedListItemName)
                        {
                            if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(cName))
                            {
                                SelectionItemPattern pattern;
                                pattern = ae.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
                                pattern.Select();
                                KeyboardOp.sendKey(" ");
                                return("Done");
                            }
                        }
                        else
                        {
                            if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == cName)
                            {
                                SelectionItemPattern pattern;
                                pattern = ae.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
                                pattern.Select();
                                KeyboardOp.sendKey(" ");
                                return("Done");
                            }
                        }
                    }
                }
            }
            else
            {
                return("ListItem not found");
            }
            return("ListItem not found");
        }
Exemplo n.º 4
0
        public static string CaptureScreen(string file, bool isCurrentWindow)
        {
            if (isCurrentWindow)
            {
                try {
                    Clipboard.Clear();
                    KeyboardOp.sendKey("%{PRTSC}");

                    Image i = Clipboard.GetImage();
                    //if (data.GetDataPresent(typeof(Bitmap))) {
                    i.Save(file, System.Drawing.Imaging.ImageFormat.Jpeg);
                    Clipboard.Clear();
                    i.Dispose();
                } catch (ThreadStateException) {
                    return("Please add [STAThread] mark");
                }
                return("Done");
            }
            else
            {
                CaptureScreen(file);
                return("Done");
            }
        }