/// <summary> /// Releases the right button of the mouse at the current cursor position. /// </summary> public override void ReleaseRight() { var input = CreateInput(); input.Mouse.Flags = MouseFlags.RightUp; WindowCore.SendInput(input); }
/// <summary> /// Makes the lParam for a key depending on several settings. /// </summary> /// <param name="key"> /// [16-23 bits] The virtual key. /// </param> /// <param name="keyUp"> /// [31 bit] The transition state. /// The value is always 0 for a <see cref="WindowsMessages.KeyDown"/> message. /// The value is always 1 for a <see cref="WindowsMessages.KeyUp"/> message. /// </param> /// <param name="fRepeat"> /// [30 bit] The previous key state. /// The value is 1 if the key is down before the message is sent, or it is zero if the key is up. /// The value is always 1 for a <see cref="WindowsMessages.KeyUp"/> message. /// </param> /// <param name="cRepeat"> /// [0-15 bits] The repeat count for the current message. /// The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. /// If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative. /// The repeat count is always 1 for a <see cref="WindowsMessages.KeyUp"/> message. /// </param> /// <param name="altDown"> /// [29 bit] The context code. /// The value is always 0 for a <see cref="WindowsMessages.KeyDown"/> message. /// The value is always 0 for a <see cref="WindowsMessages.KeyUp"/> message.</param> /// <param name="fExtended"> /// [24 bit] Indicates whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on /// an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. /// </param> /// <returns>The return value is the lParam when posting or sending a message regarding key press.</returns> /// <remarks> /// KeyDown resources: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646280%28v=vs.85%29.aspx /// KeyUp resources: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646281%28v=vs.85%29.aspx /// </remarks> private UIntPtr MakeKeyParameter(Keys key, bool keyUp, bool fRepeat, uint cRepeat, bool altDown, bool fExtended) { // Create the result and assign it with the repeat count var result = cRepeat; // Add the scan code with a left shift operation result |= WindowCore.MapVirtualKey(key, TranslationTypes.VirtualKeyToScanCode) << 16; // Does we need to set the extended flag ? if (fExtended) { result |= 0x1000000; } // Does we need to set the alt flag ? if (altDown) { result |= 0x20000000; } // Does we need to set the repeat flag ? if (fRepeat) { result |= 0x40000000; } // Does we need to set the keyUp flag ? if (keyUp) { result |= 0x80000000; } return(new UIntPtr(result)); }
public void EnumTopLevelWindowsThreadSafe() { // Arrange IEnumerable <IntPtr> handles1 = null; IEnumerable <IntPtr> handles2 = null; var r = new ManualResetEvent(false); // ReSharper disable ImplicitlyCapturedClosure var t1 = new Thread(() => // ReSharper restore ImplicitlyCapturedClosure { r.WaitOne(); handles1 = WindowCore.EnumTopLevelWindows(); }); // ReSharper disable ImplicitlyCapturedClosure var t2 = new Thread(() => // ReSharper restore ImplicitlyCapturedClosure { r.WaitOne(); handles2 = WindowCore.EnumTopLevelWindows(); }); // Act t1.Start(); t2.Start(); r.Set(); t1.Join(); t2.Join(); // Assert Assert.AreEqual(handles1.Count(), handles2.Count(), "The function is not thread-safe."); }
/// <summary> /// Presses the left button of the mouse at the current cursor position. /// </summary> public override void PressLeft() { var input = CreateInput(); input.Mouse.Flags = MouseFlags.LeftDown; WindowCore.SendInput(input); }
/// <summary> /// Scrolls vertically using the wheel of the mouse at the current cursor position. /// </summary> /// <param name="delta">The amount of wheel movement.</param> public override void ScrollVertically(int delta = 120) { var input = CreateInput(); input.Mouse.Flags = MouseFlags.Wheel; input.Mouse.MouseData = delta; WindowCore.SendInput(input); }
/// <summary> /// The run. /// </summary> /// <param name="mainWindow"> /// The main window. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public new int Run(WindowCore mainWindow = null) { if (mainWindow is IChromelyHost chromelyHost) { this.mHostConfig = chromelyHost.HostConfig; } return(base.Run(mainWindow)); }
/// <summary> /// Moves the cursor at the specified coordinate. /// </summary> /// <param name="x">The x-coordinate.</param> /// <param name="y">The y-coordinate.</param> protected override void MoveToAbsolute(int x, int y) { var input = CreateInput(); input.Mouse.DeltaX = CalculateAbsoluteCoordinateX(x); input.Mouse.DeltaY = CalculateAbsoluteCoordinateY(y); input.Mouse.Flags = MouseFlags.Move | MouseFlags.Absolute; input.Mouse.MouseData = 0; WindowCore.SendInput(input); }
public new int Run(WindowCore mainWindow = null) { if ((mainWindow != null) && (mainWindow is IChromelyHost)) { IChromelyHost chromelyHost = (IChromelyHost)mainWindow; m_hostConfig = chromelyHost.HostConfig; } return(base.Run(mainWindow)); }
public void GetClassName() { // Arrange var handle = Resources.ProcessTest.MainWindowHandle; // Act var className = WindowCore.GetClassName(handle); // Assert Assert.AreEqual("Notepad++", className, "The class name strings are not equal (or it's note Notepad++)."); }
public void Open() { if (_Style.IsModal) { WindowCore.ShowDialog(); } else { WindowCore.Show(); } }
public void GetWindowThreadId() { // Arrange var handle = Resources.ProcessTest.MainWindowHandle; // Act var threadId = WindowCore.GetWindowThreadId(handle); // Assert Assert.AreEqual(Resources.ProcessTest.Threads[0].Id, threadId, "Thread id are not equal."); // This is the case for Notepad++ }
public void SetGetWindowPlacement() { // Arrange var handle = Resources.ProcessTest.MainWindowHandle; // Act WindowCore.SetWindowPlacement(handle, 400, 400, 400, 400); var placement = WindowCore.GetWindowPlacement(handle); // Assert Assert.AreEqual(400, (placement.NormalPosition.Top + placement.NormalPosition.Left + placement.NormalPosition.Height + placement.NormalPosition.Width) / 4); }
public void EnumTopLevelWindowsCheckPrecence() { // Arrange var handle = Resources.ProcessTest.MainWindowHandle; // Act var handles = WindowCore.EnumTopLevelWindows().ToArray(); // Assert Assert.AreNotEqual(0, handles.Count(), "Cannot enumerate windows."); Assert.IsTrue(handles.Any(h => h == handle), "Cannot find the process test in the enumerated windows."); }
public void EnumChildWindows_CheckIfScintillaPresent() { // Arrange var handle = Resources.ProcessTest.MainWindowHandle; // Act var handles = WindowCore.EnumChildWindows(handle).ToArray(); // Assert Assert.AreNotEqual(0, handles.Count(), "Cannot enumerate windows."); Assert.IsTrue(handles.Any(h => WindowCore.GetClassName(h) == "Scintilla"), "Cannot find Scientilla in the enumerated windows."); }
public void SendMessageCloseWindow() { // Arrange var process = Resources.ProcessTest; // Act WindowCore.SendMessage(process.MainWindowHandle, WindowsMessages.Close, UIntPtr.Zero, IntPtr.Zero); Thread.Sleep(1000); // Assert Assert.IsTrue(process.HasExited, "The process didn't exited."); Resources.Restart(); }
public void SetGetWindowText() { // Arrange var handle = Resources.ProcessTest.MainWindowHandle; const string value = "I love cookies"; // Act WindowCore.SetWindowText(handle, value); var title = WindowCore.GetWindowText(handle); // Assert Assert.AreEqual(value, title, "Couldn't retrieve the title correctly."); Resources.Restart(); }
public void SetGetForegroundWindow() { // Arrange var handle = Resources.ProcessTest.MainWindowHandle; // Act try { WindowCore.SetForegroundWindow(handle); var ret = WindowCore.GetForegroundWindow(); Assert.AreEqual(handle, ret, "Couldn't set or get the foreground."); } catch (ApplicationException ex) { // Assert Assert.Fail(ex.Message); } }
public static void RunWindowProc(WindowCore coreWindow, ref WindowMessage msg) { msg.SetResult(coreWindow.WindowProc(msg.Hwnd, (uint)msg.Id, msg.WParam, msg.LParam)); }
/// <summary> /// Retrieves a new <see cref="Process" /> component that created the window. /// </summary> /// <param name="windowHandle">A handle to the window.</param> /// <returns> /// A <see cref="Process" />A <see cref="Process" /> component that is associated with the specified window /// handle. /// </returns> public Process FromWindowHandle(IntPtr windowHandle) { return(FromProcessId(WindowCore.GetWindowProcessId(windowHandle))); }
/// <summary> /// Creates a collection of new <see cref="Process" /> components and associates them with all the process resources /// that share the specified window title. /// </summary> /// <param name="windowTitle">The window title string.</param> /// <returns> /// A collection of type <see cref="Process" /> that represents the process resources running the specified /// application or file. /// </returns> public static IEnumerable <Process> FromWindowTitle(string windowTitle) { return(Windows.Where(window => WindowCore.GetWindowText(window) == windowTitle).Select(FromWindowHandle)); }
/// <summary> /// Creates a collection of new <see cref="Process" /> components and associates them with all the process resources /// that share the specified class name. /// </summary> /// <param name="className">The class name string.</param> /// <returns> /// A collection of type <see cref="Process" /> that represents the process resources running the specified /// application or file. /// </returns> public IEnumerable <Process> FromWindowClassName(string className) { return(Windows.Where(window => WindowCore.GetClassName(window) == className).Select(FromWindowHandle)); }
public DwmWindowHelper(WindowCore window) : base(window) { }
/// <summary> /// Creates a collection of new <see cref="Process" /> components and associates them with all the process resources /// that contain the specified window title. /// </summary> /// <param name="windowTitle">A part a window title string.</param> /// <returns> /// A collection of type <see cref="Process" /> that represents the process resources running the specified /// application or file. /// </returns> public IEnumerable <Process> FromWindowTitleContains(string windowTitle) { return (Windows.Where(window => WindowCore.GetWindowText(window).Contains(windowTitle)).Select(FromWindowHandle)); }
public DwmWindowHelperCore(WindowCore window) { this.m_window = window; }