tre*_*der 29 windows windows-7 focus window-focus
某些东西正在从我的 Windows 中的活动窗口(活动程序)转移(窃取)焦点,因为我目前正在使用它。
我在描述了同样的问题这个问题,也有一些例外:
我在(至少)两台不同的计算机上观察到了这种行为,所以这不是特定于机器的。
提到的其中一台计算机具有 Windows 7 HE 64 位,另一台具有 Windows 7 Pro 32 位,因此此问题不特定于特定版本的 Windows 或特定硬件平台。
有时焦点会永远丢失(必须单击窗口才能继续使用它),有时它只是转移到另一个后台进程(?)并在大约 2-3 秒后返回。
过去几周我没有在任何这些计算机上安装任何新的东西(除了 Windows 更新和其他自动更新,如 Chrome 浏览器自动更新),当然提到的问题在上次安装后很多天开始发生。
我电脑的当前行为真的很奇怪,整个事情变得很烦人。例子:
我在 Chrome 中选择一些文本并实际看到,选择颜色从蓝色(在活动窗口中选择)变为灰色(在非活动窗口中选择)。
我正在用 Word、Notepad++ 或 Chrome 的 Gmail 中的电子邮件编辑一些文档,编辑过程要么停止几秒钟(当焦点转移时),要么永久结束(焦点永远丢失)。
我有活动的、更新的和正在运行的Microsoft Security Essentials,它没有报告任何异常。
我有一种感觉,它最常发生在谷歌浏览器中。起初我很确定,我几乎准备指责这个浏览器的一些最新更新。但事实证明,我在 Chrome 中经常注意到这一点,因为这是我最常用的程序。
有没有人有或有过类似的问题或有任何想法,可能导致此问题或如何解决此问题?
tre*_*der 19
按照and31415的建议,我仔细查看Startup了msconfig程序选项卡中的内容,但没有发现任何异常。
现在很明显,这 99% 是由某些外部程序引起的(尽管之前没有注意到,尽管我最近没有安装任何新程序),而不是 Windows。这是我在这里最重要的一点。
我在谷歌上搜索了更多并得到了一些想法/建议,即我应该在发现焦点被偷走后立即尝试按Alt+ F4。这应该退出可能导致此焦点隐形的进程。然后,我可能会尝试使用Process Monitorfrom Sysinternalspackage 来跟踪刚刚退出的进程。
这可能让我对导致此问题的原因有所了解。
小智 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)
显示进程开始(绿色)和终止(红色)的输出示例

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 错误报告)一次又一次启动。我按照下面的解决方案阻止它自动启动,这解决了问题。
| 归档时间: |
|
| 查看次数: |
98220 次 |
| 最近记录: |