views:

298

answers:

2

I'm writing program to automate win32 form. I'm using Microsoft UI Automation library. I don't know how I can get and invoke predifined shortcuts key on that form. Now I simply get AutomationElement of the MenuItem and invoke click on that elemnt. Any solutions? Does anybody do this?

+1  A: 

As far as I know AutomationElementInformation has an AcceleratorKey and AccessKey properties.
Some extractions from MSDN:

AutomationElement::AutomationElementInformation::AcceleratorKey
The sequence of key combinations that invoke an action associated with the element.

and:

AutomationElement::AutomationElementInformation::AccessKey
The character, associated with an element, that is used to activate that element.

And after you can use SendKeys to simulate key pressings.

Another way is to use keybd___event but, AFAIK, it was deprecated and Microsoft advises to use SendInput instead. May be it will help you.

Mihail
Thanks about AcceleratorKey and AccessKey. It was helpful.But I can't use SendKeys, because using UI Automation Library is another approach when working with Win32 Form.I have AutomationElemnt and can get its patterns to interact with control type properties.In my case, I have MainWindow AutomationElement and it has two patterns availeble: WindowPattern and TransformPattern. And using this pattern there is no way to emulate SendKeys.So, I stil doesn't understand how I can use key shortcuts.
Loki
Can you use *SendInput*?
Mihail
A: 

You should active the main window, and call the SendKeys::Send to send the keys to the active window. It's a static method in SendKeys class, so, send the keys to window no need the main window's AutomationElement.

yufun