Re: setting application and window focus
Re: setting application and window focus
- Subject: Re: setting application and window focus
- From: John Louch <email@hidden>
- Date: Wed, 29 Mar 2006 10:14:14 -0800
- Thread-topic: setting application and window focus
Generally this is a bad idea. The problem is that the front most process
might have changed since your stored away the front most psn.
What you should try to do is never come to the front. In cocoa you get this
somewhat for free by being a nonactivating panel. There might be a solution
for carbon as well.
Thanks,
jl
> Thanks to Tom Bunch and Ian Archer for supplying this answer. It
> worked like a charm.
>
> Yes, some of those calls were failing, and even the ones that
> succeeded didn't succeed in focusing on the correct app.
>
> Cheers!
> Keith
>
> On Mar 29, 2006, at 11:05 AM, Tom Bunch wrote:
>
>> I realize that you may have omitted code, but some of these should
>> be failing with kAXErrorIllegalArgument. Are you checking theErr?
>>
>> That said, I don't actually know if there is an Accessibility API
>> that lets you set the focused app. I would try
>>
>> extern OSErr GetFrontProcess(ProcessSerialNumber * PSN);
>> extern OSErr SetFrontProcess(ProcessSerialNumber * PSN);
>>
>> -Tom
>>
>> On Mar 29, 2006, at 8:41 AM, Keith Alperin wrote:
>>
>>> Greetings Accessibility-devs!
>>>
>>> I have a cocoa agent application (one that does not show up in the
>>> dock, though it can come forward and present a UI). I use a hot
>>> key to bring up a window from my agent app and then do something.
>>> When it is done, i hide the window and want to return focus the
>>> previously focused window. I keep AXUIElementRefs of the focused
>>> Application, window and even kAXFocusedUIElementAttribute from
>>> before i change focus to my agent app. I've tried a number of
>>> ways to return focus to the original window, but none of them seem
>>> to work:
>>>
>>> theErr = AXUIElementSetAttributeValue
>>> (previouslyFocusedApplication, kAXMainAttribute, kCFBooleanTrue);
>>> theErr = AXUIElementSetAttributeValue
>>> (previouslyFocusedApplication, kAXFocusedApplicationAttribute,
>>> kCFBooleanTrue);
>>> theErr = AXUIElementSetAttributeValue(previouslyFocusedWindow,
>>> kAXFocusedWindowAttribute, kCFBooleanTrue);
>>> theErr = AXUIElementSetAttributeValue(previouslyFocusedWindow,
>>> kAXMainAttribute, kCFBooleanTrue);
>>> theErr = AXUIElementSetAttributeValue(previouslyFocusedWindow,
>>> kAXFocusedAttribute, kCFBooleanTrue);
>>> theErr = AXUIElementSetAttributeValue
>>> (previouslyFocusedApplication, kAXFocusedUIElementAttribute,
>>> previouslyFocusedElement);
>>>
>>> after each of these, i check what the
>>> kAXFocusedApplicationAttribute of the system wide element is and
>>> it's always my agent application. I'm not that experienced with
>>> the Accessibility API, is there a simple way to set the focus of a
>>> specific application and window?
>>>
>>> Many thanks,
>>> Keith R. Alperin
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Accessibility-dev mailing list (Accessibility-
>>> email@hidden)
>>> Help/Unsubscribe/Update your Subscription:
>>> 40omnigroup.com
>>>
>>> This email sent to email@hidden
>>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Accessibility-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
--------------------------------------------------
John Louch Internet #: email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden