Quantcast
Channel: Windows Desktop Development for Accessibility and Automation forum
Viewing all articles
Browse latest Browse all 585

AutomationFocusChangedEventHandler method is calling only once

$
0
0

Hello 

I am working on a Automation Project. I have a requirement to trace the elements on which I focused the mouse.

Here is a Start() method to start listening the AutomationFocusChangedEvent:

        public void Start()
        {
            //check if we are tracing
            if (_isFocusTracing == true)
                throw new InvalidOperationException("cannot call StartFocusTracing mutliple times");

            using (new WaitCursor())
            {
                try
                {
                    //set the event handler
                    Automation.AddAutomationFocusChangedEventHandler(new AutomationFocusChangedEventHandler(OnAutomationFocusChanged));
                    _isFocusTracing = true;
                    OnStartFocusTracing();
                }
                catch (Exception ex)
                {
                     ApplicationLogger.LogException(ex);
                    _isFocusTracing = false;
                }
            }
        }

And here is a handler method for AutomationFocusChangedEvent:

        private void OnAutomationFocusChanged(object src, AutomationFocusChangedEventArgs e)
        {
            Debug.WriteLine("OnAutomationFocusChanged ...");

            OnAutomationFocusChanged((AutomationElement)src);
        }

The problem with the above code is that, the handler method OnAutomationFocusChangedis only called for the first element that I focused. For further focused elements, handler method is not called. That means, this method is calling only once. [Here, I am focusing the elements from external Windows application]

Could you please tell me where I am going wrong in this case?

Thank you in advance!


Viewing all articles
Browse latest Browse all 585

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>