Is there a way to copy text from another program without a choice?

I want to copy text from another program, in this program Ctrl + a is considered for another command, and I cannot use "SendKeys.SendWait" ("^ a"); to select text.

Is there any way to copy this text?

+4
source share
2 answers

You can do this using UIAComWrapper , you will need to process this window (where you are trying to copy from) and the information about this element, which you can get from UIAutomationVerify .

var elementCollection = AutomationElement.FromHandle(windowHandle).FindAll(TreeScope.Subtree, Condition.TrueCondition);
foreach (var item in elementCollection)
{
   //check item properties if element is the one you looking for
}

Alternatively, instead, Condition.TrueConditionyou can provide a more sophisticated filter to get only one item.

, :

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
const string InternetExplorerClass = "IEFrame";
static void Main()
{
    var windowHandle = new IntPtr(0);

    //Find internet explorer instance
    windowHandle = FindWindow(InternetExplorerClass, null);

    if (!windowHandle.Equals(IntPtr.Zero))
    {
        //create filter to improve search speed
        var localizedControlType = new PropertyCondition(
            AutomationElement.LocalizedControlTypeProperty,
            "tab item");

        //get all elements in internet explorer that match our filter
        var elementCollection =
            AutomationElement.FromHandle(windowHandle)
                .FindAll(TreeScope.Subtree, localizedControlType);

        //iterate through search results
        foreach (AutomationElement item in elementCollection)
        {
            Console.WriteLine(item.Current.Name);
        }
    }
    else
    {
        Console.WriteLine("Internet explorer not found");
    }

    Console.ReadLine();
}

Internet Explorer . GitHub.

+1

? , :  1.  2. Ctrl + Shift + End  3. Ctrl + C

Windows

0

All Articles