1

Iam working on a project that need to get selected text from other application anytime user selects some text.

I have used globalmousekeyhook to monitor when user clicks on an application and i have not problem with that.

My problem is with getting selected text, As i know there are two ways to get selected text from other Applications:

1-Sending copy command(like this):
This way works on clipboard and causes some problems with some applications like Adobe reader (problem),IDM (clipboard links) And other applications that also work on clipboard.

2-Using UI Automation:
As i have tried and seen that this way cant be used for get selected text from ANY window (using UI Automation)

I also edited this code like bellow but it still not working and slows down my computer

Process p = Process.GetCurrentProcess();

AutomationElement ae = AutomationElement.FromHandle(p.MainWindowHandle);

AutomationElement npEdit = ae.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "Edit"));

TextPattern tp = npEdit.GetCurrentPattern(TextPattern.Pattern) as TextPattern;

TextPatternRange[] trs;

if (tp.SupportedTextSelection == SupportedTextSelection.None)
{
      return;
}
else
{
      trs = tp.GetSelection();
      label1.Text = trs[0].GetText(-1);
}


Isn't there another way to get selected text from other applications?
Or second way can't be used to perform the work?

Thanks for any help...

Community
  • 1
  • 1
Hamreen Ahmad
  • 522
  • 5
  • 21

1 Answers1

0

An approach might be the use of Spy++. Get the handle, extract and parse data you need.

Jan
  • 108
  • 1
  • 7