Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:07:44+00:00 2026-06-08T14:07:44+00:00

Well Sometimes I am typing and very rarely it happens that something steals focus,

  • 0

Well Sometimes I am typing and very rarely it happens that something steals focus, I read some solution (even a VB watch) but they don’t apply to me. Is there any windows-wide ‘handle’ which handles ANY focus changes?

It doesn’t matter in which language, C, C++, VB.NET, C#, Anything .NET or windows related, Batch, PoweShell, VBS Script… As Long as I am able to monitor every focus change and log it into a file/cmd window/visual window.

Something like:

   void event_OnWindowsFocusChange(int OldProcID, int NewProcID);

would be very usefull. Or maybe there are tools for this already (which I can’t find?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:07:46+00:00Added an answer on June 8, 2026 at 2:07 pm

    One way would be to use the windows UI Automation API. It exposes a global focus changed event. Here is a quick sample I came up with (in C#). Note, you need to add references to UIAutomationClient and UIAutomationTypes.

    using System.Windows.Automation;
    using System.Diagnostics;
    
    namespace FocusChanged
    {
        class Program
        {
            static void Main(string[] args)
            {
                Automation.AddAutomationFocusChangedEventHandler(OnFocusChangedHandler);
                Console.WriteLine("Monitoring... Hit enter to end.");
                Console.ReadLine();
            }
    
            private static void OnFocusChangedHandler(object src, AutomationFocusChangedEventArgs args)
            {
                Console.WriteLine("Focus changed!");
                AutomationElement element = src as AutomationElement;
                if (element != null)
                {
                    string name = element.Current.Name;
                    string id = element.Current.AutomationId;
                    int processId = element.Current.ProcessId;
                    using (Process process = Process.GetProcessById(processId))
                    {
                        Console.WriteLine("  Name: {0}, Id: {1}, Process: {2}", name, id, process.ProcessName);
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well I noticed that on Windows 7, sometimes even when you are an administrator,
This is weird.. I've a DefaultHandler that is actually handling everything well but sometimes,
I see some examples sometimes would declare a property as well as variable other
I'm having some problems with ActiveRecord. Well everything works fine, but it's working sometimes.
I read sometimes from people that seem to be working with rails since longer,
Some sql is not well written. Sometimes a search costs hours in applications. When
I have a listbox which (sometimes) uses OptionGroups as well, meaning that if I
Well to me Perl sometimes looks abit Abracadabra so many thanks for the patience
Well,i have a weird question to ask,sometimes when designing a form and using lots
I have completed the well known 'news' toutorial included in CI documentation. sometimes double

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.