public void PerformClickJs(double relativeX, double relativeY) { var rect = new Native.Rect(); Native.GetWindowRect(Hwnd, ref rect); var windowWidth = rect.Right - rect.Left; var windowHeight = rect.Bottom - rect.Top; var clickX = windowWidth * relativeX + TrimMargin.Left + rect.Left; var clickY = windowHeight * relativeY + TrimMargin.Top + rect.Top; MouseClickHelper.Click((int)clickX, (int)clickY); }
private byte[] GetImage(IntPtr hwnd, TrimMargin trimMargin) { var rect = new Native.Rect(); Native.GetWindowRect(hwnd, ref rect); byte[] bytes = new byte[0]; if (rect.Left == 0 && rect.Top == 0 && rect.Right == 0 && rect.Bottom == 0) { return(null); } trimMargin ??= new TrimMargin(); var width = rect.Right - rect.Left - trimMargin.Left - trimMargin.Right; var height = rect.Bottom - rect.Top - trimMargin.Top - trimMargin.Bottom; if (width < 0 || height < 0) { return(null); } using (var memoryStream = new MemoryStream()) using (var bitmap = new Bitmap(width, height)) using (var graphic = Graphics.FromImage(bitmap)) { graphic.CompositingQuality = CompositingQuality.HighSpeed; graphic.CompositingMode = CompositingMode.SourceCopy; graphic.CopyFromScreen(rect.Left + trimMargin.Left, rect.Top + trimMargin.Top, 0, 0, bitmap.Size, CopyPixelOperation.SourceCopy); bitmap.Save(memoryStream, ImageFormat.Jpeg); bytes = new byte[memoryStream.Length]; memoryStream.Seek(0, SeekOrigin.Begin); memoryStream.Read(bytes, 0, bytes.Length); } GC.Collect(); GC.WaitForPendingFinalizers(); return(bytes); }
/// <summary> /// Catches the Hotkeys /// </summary> protected override void WndProc(ref Message m) { if (m.Msg == Native.WM_HOTKEY) { var keystroke = ((uint)m.LParam >> 16) & 0x0000FFFF; var keystrokeModifier = (uint)m.LParam & 0x0000FFFF; // Global hotkey to make a window borderless if (keystroke == MakeBorderlessHotKey && keystrokeModifier == MakeBorderlessHotKeyModifier) { // Find the currently-active window var hCurrentActiveWindow = Native.GetForegroundWindow(); // Only if that window isn't Borderless Windows itself if (hCurrentActiveWindow != Handle) { // Figure out the process details based on the current window handle var pd = _watcher.FromHandle(hCurrentActiveWindow); if (pd == null) { Task.WaitAll(_watcher.Refresh()); pd = _watcher.FromHandle(hCurrentActiveWindow); if (pd == null) { return; } } // If we have information about this process -and- we've already made it borderless, then reverse the process if (pd.MadeBorderless) { Manipulation.RestoreWindow(pd); } // Otherwise, this is a fresh request to remove the border from the current window else { _watcher.RemoveBorder(pd).GetAwaiter().GetResult(); } } return; // handled the message, do not call base WndProc for this message } if (keystroke == MouseHideHotKey && keystrokeModifier == MouseHideHotKeyModifier) { Manipulation.ToggleMouseCursorVisibility(this); return; // handled the message, do not call base WndProc for this message } if (keystroke == MouseLockHotKey && keystrokeModifier == 0) { var hWnd = Native.GetForegroundWindow(); // get size of clientarea var rect = new Native.Rect(); Native.GetClientRect(hWnd, ref rect); // get top,left point of clientarea var p = new Native.POINTAPI { X = 0, Y = 0 }; Native.ClientToScreen(hWnd, ref p); var clipRect = new Rectangle(p.X, p.Y, rect.Right - rect.Left, rect.Bottom - rect.Top); Cursor.Clip = Cursor.Clip.Equals(clipRect) ? Rectangle.Empty : clipRect; return; // handled the message, do not call base WndProc for this message } } base.WndProc(ref m); }