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 { } }
public static void StopMonitoringActiveAppChanges() { if (CurrentHook != IntPtr.Zero) { UnhookWinEvent(CurrentHook); CurrentHook = IntPtr.Zero; KeyboardManager.EnableSystemKeys(); } }
protected override void OnDeactivated(EventArgs e) { base.OnDeactivated(e); KeyboardManager.EnableSystemKeys(); WindowsManager.StartMonitoringActiveAppChangesIfNeeded(); }