private static void OnActiveWindowChanged(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { try { bool disabled = false; var file = MustHookFile; if (file.Exists) { var processesToHook = File.ReadAllLines(file.FullName); if (processesToHook.Length > 0) { uint pid; GetWindowThreadProcessId(hwnd, out pid); Process p = Process.GetProcessById((int)pid); var activeProcessFile = new FileInfo(p.MainModule.FileName); if (processesToHook.Contains(activeProcessFile.Name)) { KeyboardManager.DisableSystemKeys(null); disabled = true; } } } if (!disabled && !IsCurrentAppActive()) { KeyboardManager.EnableSystemKeys(); } } catch { } }
protected override void OnActivated(EventArgs e) { base.OnActivated(e); KeyboardManager.DisableSystemKeys(this.VisualTreeChildren <IHandleKeyboardHookControl>().ToList()); }