活动窗口(程序)在 Windows 7 中意外失去焦点

tre*_*der 29 windows windows-7 focus window-focus

某些东西正在从我的 Windows 中的活动窗口(活动程序)转移(窃取)焦点,因为我目前正在使用它。

我在描述了同样的问题这个问题,也有一些例外:

  1. 我在(至少)两台不同的计算机上观察到了这种行为,所以这不是特定于机器的。

  2. 提到的其中一台计算机具有 Windows 7 HE 64 位,另一台具有 Windows 7 Pro 32 位,因此此问题不特定于特定版本的 Windows 或特定硬件平台。

  3. 有时焦点会永远丢失(必须单击窗口才能继续使用它),有时它只是转移到另一个后台进程(?)并在大约 2-3 秒后返回。

  4. 过去几周我没有在任何这些计算机上安装任何新的东西(除了 Windows 更新和其他自动更新,如 Chrome 浏览器自动更新),当然提到的问题在上次安装后很多天开始发生

我电脑的当前行为真的很奇怪,整个事情变得很烦人。例子:

  1. 我在 Chrome 中选择一些文本并实际看到,选择颜色从蓝色(在活动窗口中选择)变为灰色(在非活动窗口中选择)。

  2. 我正在用 Word、Notepad++ 或 Chrome 的 Gmail 中的电子邮件编辑一些文档,编辑过程要么停止几秒钟(当焦点转移时),要么永久结束(焦点永远丢失)。

我有活动的、更新的和正在运行的Microsoft Security Essentials,它没有报告任何异常。

我有一种感觉,它最常发生在谷歌浏览器中。起初我很确定,我几乎准备指责这个浏览器的一些最新更新。但事实证明,我在 Chrome 中经常注意到这一点,因为这是我最常用的程序。

有没有人有或有过类似的问题或有任何想法,可能导致此问题或如何解决此问题?

tre*_*der 19

按照and31415的建议,我仔细查看Startupmsconfig程序选项卡中的内容,但没有发现任何异常。

现在很明显,这 99% 是由某些外部程序引起的(尽管之前没有注意到,尽管我最近没有安装任何新程序),而不是 Windows。这是我在这里最重要的一点。

我在谷歌上搜索了更多并得到了一些想法/建议,即我应该在发现焦点被偷走后立即尝试按Alt+ F4。这应该退出可能导致此焦点隐形的进程。然后,我可能会尝试使用Process Monitorfrom Sysinternalspackage 来跟踪刚刚退出的进程。

这可能让我对导致此问题的原因有所了解。

  • 从“msconfig”中,选择“**服务**”选项卡并启用“**隐藏所有 Microsoft 服务**”。也检查一下。以下是一篇可能有用的官方知识库文章:[执行干净启动以确定后台程序是否干扰您的游戏或程序](http://support.microsoft.com/kb/331796)。另外,即使您没有看到任何异常情况,我认为列出您获得的所有第三方启动项目和服务也是一个好主意。 (2认同)
  • 使用“进程监视器”时,转到“过滤器”菜单并添加以下过滤器:操作不是“进程退出”,然后是“排除”。我的触摸板驱动程序抛出错误并尝试使用 Windows 问题报告进行报告。感谢 %#!@ 提供这些问答网站,否则我会毁了我的笔记本电脑。 (2认同)

小智 12

我编写了一个 C# 程序来监视波动的过程。如果有人需要找出导致此问题的进程,这里是代码。

using System;
using System.Diagnostics;
using System.Linq;

namespace ProcessMonitor
{
    class Program
    {
        static void Main(string[] args)
        {
            var lastPros = Process.GetProcesses().Select((x) => x.Id).ToList();
            var oldProcessList = Process.GetProcesses();
            while (true)
            {
                var processlist = Process.GetProcesses();

                var currentPros = processlist.Select(x => x.Id).ToList();
                var diff = lastPros.Except(currentPros).ToList();
                Console.ForegroundColor = ConsoleColor.Red;

                var pro = oldProcessList.Where(x => diff.Contains(x.Id)).ToList();

                if (diff.Count == 0)
                {
                    pro = processlist.Where((x) => diff.Contains(x.Id)).ToList();
                    diff = currentPros.Except(lastPros).ToList();
                    Console.ForegroundColor = ConsoleColor.Green;
                    pro = processlist.Where((x) => diff.Contains(x.Id)).ToList();
                }
                foreach (var oldPid in diff)
                {
                    Console.Write("PID {0}", oldPid);
                    try
                    {
                        Console.WriteLine(" name {0}", pro.Where((x) => x.Id == oldPid).ToList()[0].ProcessName);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($" Hit exception {e}");
                    }
                }
                if (diff.Count > 0)
                {
                    lastPros = currentPros;
                    oldProcessList = processlist;
                }
                System.Threading.Thread.Sleep(100);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

显示进程开始(绿色)和终止(红色)的输出示例

输出样本

  • 好主意和不错的代码。但是,由于这是 _users_ 的站点,而不是开发人员的站点(这是超级用户,而不是 Stack Overflow),那么您应该添加一些关于非 C# 开发人员如何能够运行您的代码的解释? (15认同)

Pal*_*lec 10

焦点可能被错误的后台任务窃取了。它打开一个窗口,窃取焦点,并且很快关闭,但焦点不返回。最近,Microsoft Office 出现了这样的错误

发现这样的过程中,你可以使用的工具窗口焦点记录仪)或类似的自定义的C#程序进程监视器

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ProcessMonitor
{
    class Program
    {
        const int pollDelay = 100;

        static void Main(string[] args)
        {
            var lastProcesses = GetDescriptions();
            while (true)
            {
                System.Threading.Thread.Sleep(pollDelay);
                var now = DateTime.Now;
                var processes = GetDescriptions();

                var started = processes.Except(lastProcesses);
                var stopped = lastProcesses.Except(processes);

                foreach (var p in started)
                {
                    Print(now, p, ConsoleColor.Green);
                }
                foreach (var p in stopped)
                {
                    Print(now, p, ConsoleColor.Red);
                }

                lastProcesses = processes;
            }
        }

        static void Print(DateTime dateTime, ProcessDescription process,
            ConsoleColor color)
        {
            Console.ForegroundColor = color;
            Console.WriteLine("{0:hh\\:mm\\:ss\\.ff}\tPID {1}\t{2}",
                dateTime.TimeOfDay, process.Id, process.Description);
            Console.ResetColor();
        }

        static List<ProcessDescription> GetDescriptions()
        {
            return Process.GetProcesses().Select(x => GetDescription(x)).ToList();
        }

        static ProcessDescription GetDescription(Process p)
        {
            int pid = -1;
            string description;
            try
            {
                pid = p.Id;
                description = p.ProcessName;
            }
            catch (Exception e)
            {
                description = "Hit exception " + e;
            }
            return new ProcessDescription { Id = pid, Description = description };
        }

        struct ProcessDescription
        {
            public int Id;
            public string Description;

            public override bool Equals(object obj)
            {
                return obj != null && Id == ((ProcessDescription)obj).Id;
            }
            public override int GetHashCode()
            {
                return Id.GetHashCode();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Omar Alshaker 提供的代码的改进和错误修正版本。也不需要 C# 6。需要 .NET 3.5 或更新版本。

您可以使用csc.exe.NET Framework 安装附带的 C# 编译器 ( )对其进行编译,并运行生成的可执行文件以获取开始(绿色)或结束(红色)进程的实时日志。使用Ctrl+C终止它。


要查找编译器,请运行where /R %windir%\Microsoft.NET csc.exe. 从安装的最新 .NET 版本中选择一个,无论是 32b 还是 64b。保存 C# 代码Program.cs并将其编译为Program.exe

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe Program.cs
Run Code Online (Sandbox Code Playgroud)


小智 5

就我而言,是 wemgr.exe(Windows 错误报告)一次又一次启动。我按照下面的解决方案阻止它自动启动,这解决了问题。

  1. “开始”按钮 -> 在搜索框中输入“操作中心” -> Enter
  2. 单击“维护”旁边的箭头展开。
  3. “检查问题报告的解决方案”下,单击“设置”
  4. 单击更改所有用户的报告设置
  5. 检查每次出现问题时,在检查解决方案之前询问我旁边的单选按钮。
  6. 单击“确定”即可退出。