public static void ReloadItemfilter() { // store current clipboard string oldClipboard = Clipboard.GetText(); string chatCommand = BuildChatCommand(); if (chatCommand is null) { return; } Clipboard.SetText(BuildChatCommand()); var poeWindow = FindWindow(null, "Path of Exile"); if (poeWindow == IntPtr.Zero) { UserWarning.WarnUser("Could not find Window! Please make sure Path of Exile is running.", "Window not found"); return; } // get Path of Exile in the foreground to actually sendKeys to it SetForegroundWindow(poeWindow); // send the chat commands System.Windows.Forms.SendKeys.SendWait("{ENTER}"); System.Windows.Forms.SendKeys.SendWait("^(v)"); System.Windows.Forms.SendKeys.SendWait("{ENTER}"); // restore clipboard Clipboard.SetText(oldClipboard); }
private static string BuildChatCommand() { string filterName = GetFilterName().Trim(); Trace.WriteLine("filtername", filterName); if (String.IsNullOrEmpty(filterName)) { UserWarning.WarnUser("No filter found. Please set your filter in settings", "No filter found"); return(null); } return("/itemfilter " + filterName); }
private static string BuildFilterReloadCommand() { var filterName = GetFilterName(); if (!string.IsNullOrEmpty(filterName)) { return("/itemfilter " + filterName); } UserWarning.WarnUser("No filter found. Please set your filter in settings", "No filter found"); return(null); }
public static void ReloadFilter() { // Saving state of current clipboard // TODO How does this work if you have non-text on your clipboard? var oldClipboard = Clipboard.GetText(); var chatCommand = BuildFilterReloadCommand(); if (chatCommand is null) { return; } Clipboard.SetDataObject(chatCommand); // Map all current window names to their associated "handle to a window" pointers (HWND) var openWindows = GetOpenWindows(); foreach (var window in openWindows) { var handle = window.Key; var title = window.Value; Console.WriteLine("{0}: {1}", handle, title); } // Find the Process ID associated with the 'Path of Exile' game window var poeWindow = openWindows.FirstOrDefault(x => x.Value == "Path of Exile").Key; if (poeWindow == HWND.Zero) { UserWarning.WarnUser("Could not find Window! Please make sure Path of Exile is running.", "Window not found"); return; } // Get 'Path of Exile' window in the foreground to actually send input to said window SetForegroundWindow(poeWindow); // Compose a series of commands we send to the game window (the in-game chat box, specifically) SendKeys.SendWait("{ENTER}"); SendKeys.SendWait("^(v)"); SendKeys.SendWait("{ENTER}"); // restore clipboard Clipboard.SetDataObject(oldClipboard); }
public static void ReloadFilter() { // Saving state of current clipboard // TODO How does this work if you have non-text on your clipboard? var oldClipboard = Clipboard.GetText(); var chatCommand = BuildFilterReloadCommand(); if (chatCommand is null) { return; } // The reason for this 'retry' loop is issues caused by the .NET implementation of the clipboard // A delay in opening the clipboard causes the error, which usually passes within a few milliseconds. // REF: https://stackoverflow.com/a/69081 for (var i = 0; i < 10; i++) { try { Clipboard.SetDataObject(chatCommand); } catch (COMException ex) { const uint CLIPBRD_E_CANT_OPEN = 0x800401D0; if ((uint)ex.ErrorCode != CLIPBRD_E_CANT_OPEN) { throw; } } System.Threading.Thread.Sleep(10); } // Map all current window names to their associated "handle to a window" pointers (HWND) var openWindows = GetOpenWindows(); foreach (var window in openWindows) { var handle = window.Key; var title = window.Value; Console.WriteLine("{0}: {1}", handle, title); } // Find the Process ID associated with the 'Path of Exile' game window var poeWindow = openWindows.FirstOrDefault(x => x.Value == "Path of Exile").Key; if (poeWindow == HWND.Zero) { UserWarning.WarnUser("Could not find Window! Please make sure Path of Exile is running.", "Window not found"); return; } // Get 'Path of Exile' window in the foreground to actually send input to said window SetForegroundWindow(poeWindow); // Compose a series of commands we send to the game window (the in-game chat box, specifically) SendKeys.SendWait("{ENTER}"); SendKeys.SendWait("^(v)"); SendKeys.SendWait("{ENTER}"); // restore clipboard Clipboard.SetDataObject(oldClipboard); }