public static bool BringWindowIntoFocus(IntPtr hWnd, CharacterProfile profile = null) { if (NativeMethods.GetForegroundWindow() == hWnd) { return(true); } NativeMethods.SetForegroundWindow(hWnd); var sw = Stopwatch.StartNew(); do { if (sw.Elapsed > TimeSpan.FromSeconds(5)) { Action <string> log; if (profile != null) { log = profile.Log; } else { log = Log.Write; } var winName = NativeMethods.GetWindowText(hWnd); log($"Unabled to bring {(!string.IsNullOrEmpty(winName) ? $"{winName} " : "")}window into focus"); return(false); } Thread.Sleep(10); } while (NativeMethods.GetForegroundWindow() != hWnd); return(true); }
public TaskManager(CharacterProfile profile) { Profile = profile; WowManager = new WowManager(profile); HonorbuddyManager = new HonorbuddyManager(profile); Tasks = profile.Tasks; StartupSequenceIsComplete = IsRunning = false; HonorbuddyManager.OnStartupSequenceIsComplete += HonorbuddyManager_OnStartupSequenceIsComplete; }
private void AddAccountButton_Click(object sender, RoutedEventArgs e) { var character = new CharacterProfile(); if (AccountGrid.SelectedItem != null) character.Settings = ((CharacterProfile)AccountGrid.SelectedItem).Settings.ShadowCopy(); if (character.Settings != null) { HbRelogManager.Settings.CharacterProfiles.Add(character); AccountGrid.SelectedItem = character; EditAccount(character.Settings); } }
private void AddAccountButton_Click(object sender, RoutedEventArgs e) { var character = new CharacterProfile(); if (AccountGrid.SelectedItem != null) { character.Settings = ((CharacterProfile)AccountGrid.SelectedItem).Settings.ShadowCopy(); } if (character.Settings != null) { HbRelogManager.Settings.CharacterProfiles.Add(character); AccountGrid.SelectedItem = character; EditAccount(character.Settings); } }
public static async Task CloseBotProcessAsync(Process proc, CharacterProfile profile) { var procName = proc.ProcessName; profile.Log("Attempting to close {0}", procName); proc.CloseMainWindow(); if (await WaitForProcessToExitAsync(proc, TimeSpan.FromSeconds(10))) { profile.Log("Successfully closed {0} gracefully", procName); return; } profile.Log("Killing {0}", procName); proc.Kill(); }
private static bool ClickAtPos( IntPtr hWnd, int x, int y, bool left, bool doubleClick = false, bool restore = true, Func <bool> restoreCondition = null, CharacterProfile profile = null) { var wndBounds = GetWindowRect(hWnd); double fScreenWidth = NativeMethods.GetSystemMetrics(NativeMethods.SystemMetric.SM_CXSCREEN) - 1; double fScreenHeight = NativeMethods.GetSystemMetrics(NativeMethods.SystemMetric.SM_CYSCREEN) - 1; var fx = (wndBounds.Left + x) * (65535.0f / fScreenWidth); var fy = (wndBounds.Top + y) * (65535.0f / fScreenHeight); var structInput = new NativeMethods.Input { type = NativeMethods.SendInputEventType.InputMouse }; structInput.mkhi.mi.dwFlags = NativeMethods.MouseEventFlags.ABSOLUTE | NativeMethods.MouseEventFlags.MOVE; structInput.mkhi.mi.dx = (int)fx; structInput.mkhi.mi.dy = (int)fy; var forefroundWindow = NativeMethods.GetForegroundWindow(); if (restore) { SaveForegroundWindowAndMouse(); } if (!BringWindowIntoFocus(hWnd, profile)) { return(false); } try { NativeMethods.BlockInput(true); // check one last time if window is still in foreground after we block input. if (NativeMethods.GetForegroundWindow() != hWnd) { return(false); } NativeMethods.SendInput(1, ref structInput, SizeOfInput); Thread.Sleep(80); if (left) { structInput.mkhi.mi.dwFlags = NativeMethods.MouseEventFlags.LEFTDOWN | NativeMethods.MouseEventFlags.LEFTUP; } else { structInput.mkhi.mi.dwFlags = NativeMethods.MouseEventFlags.RIGHTDOWN | NativeMethods.MouseEventFlags.RIGHTUP; } NativeMethods.SendInput(1, ref structInput, SizeOfInput); SleepForMouseInputReaction(); if (doubleClick) { NativeMethods.SendInput(1, ref structInput, SizeOfInput); SleepForMouseInputReaction(); } } finally { if (restore) { try { if (restoreCondition != null) { while (!restoreCondition()) { Thread.Sleep(1); } } else { Thread.Sleep(100); } RestoreForegroundWindowAndMouse(); } catch { } } NativeMethods.BlockInput(false); } return(true); }
public static bool LeftClickAtPos( IntPtr hWnd, int x, int y, bool doubleClick = false, bool restore = true, Func <bool> restoreCondition = null, CharacterProfile profile = null) { return(ClickAtPos(hWnd, x, y, true, doubleClick, restore, restoreCondition, profile)); }
public ProfileEventArgs(CharacterProfile profile) { Profile = profile; }