2

I am researching the Microsoft UIAutomation for controlling text, but am finding it useless. I need to do things like:

  • Get caret position
    • This article implies to me that I need to track the caret, which will not work if I do not know it's original position....
  • Insert text in a specific location
    • Only found the ability to overwrite the entire field using ValuePattern's SetValue
  • Set font weight
    • I can read the font weight, but cannot set it
  • etc

I have read a number of articles by this point, and none point to the possibility of these. This SO question was helpful to get me started, however when I tried to dig deeper I kept running into more questions than answers. Is my only option to go to MS Accessibility Automation, which does not play well with WPF virtualization among other things.

If anybody can point me to a useful article or provide examples for the above shortcomings, that would be great. However, I am not hopeful at this point as it all seems to lead to ways to get information, but not update information.

EDIT

I have even tried to dig into the UIAutomationClient.dll and it seems that there is, indeed no support for this. It seems UIA is primarily for pulling cursory information and clicking around. No real text support

Here is another SO question...relatively similar to this one...it seems to verify that UIA is useless for my needs..

Hacky Workaround

The workaround we have is to get the general context using UIA and then using AutoIt SendKeys

Community
  • 1
  • 1
Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
  • I've just spent a few hours looking for this too. Your post relieves my frustration - I'll avoid UI Automation for this. – Govert May 09 '13 at 20:52

1 Answers1

0

The article you're pointing to describes how applications that want to support TextPattern for UI Automation need to work, not how clients that want to retrieve information using TextPattern need to work. In particular, implementers need to track the caret; clients do not.

That being said, TextPattern is designed to retrieve info, not to set it; having worked extensively with Text Services Framework, which is designed to insert text, I can understand why. (Many applications aren't designed to allow arbitrary unsolicited manipulations of their data structures; allowing applications to dictate when they can be manipulated severely contorts the design of the text service.)

The first two items are pretty straightforward. You can get the selected text using IUIAutomationTextPattern::GetSelection; this returns a collection of text ranges that you can extract the location of, etc.

While you can't directly manipulate the contents of a text range, you can select it and then generate input using SendKeys, et al.

Eric Brown
  • 13,774
  • 7
  • 30
  • 71