public PointInfo(List <Point> touchLocation, List <List <Point> > points) { _touchLocation = touchLocation; _window = SystemWindow.FromPointEx(_touchLocation[0].X, _touchLocation[0].Y, true, false); _windowHandle = _window == null ? IntPtr.Zero : _window.HWnd; Points = points; }
private SelectableTreeNodeData SelectFromPoint(int lastX, int lastY) { if (selAccObjs.Checked) { SystemAccessibleObject sao = SystemAccessibleObject.FromPoint(lastX, lastY); return(new AccessibilityData(this, sao)); } else { SystemWindow sw = SystemWindow.FromPointEx(lastX, lastY, selToplevel.Checked, false); if (!heuristicSearch.Checked && !selToplevel.Checked) { sw = SystemWindow.FromPoint(lastX, lastY); } if (sw != highlightedWindow) { if (highlightedWindow != null) { highlightedWindow.Refresh(); highlightedWindow = null; } if (sw.HWnd != this.Handle && !sw.IsDescendantOf(new SystemWindow(this.Handle))) { sw.Highlight(); highlightedWindow = sw; } } return(new WindowData(this, sw)); } }
protected void PointCapture_CaptureStarted(object sender, PointsCapturedEventArgs e) { var pointCapture = (IPointCapture)sender; if (pointCapture.Mode == CaptureMode.Training) { return; } if (VersionHelper.IsWindows8OrGreater() && !VersionHelper.IsWindows10OrGreater()) { IntPtr hwndCharmBar = FindWindow("NativeHWNDHost", "Charm Bar"); var window = SystemWindow.FromPointEx(SystemWindow.DesktopWindow.Rectangle.Right - 1, 1, true, true); if (window != null && window.HWnd.Equals(hwndCharmBar)) { e.Cancel = false; e.BlockTouchInputThreshold = 0; return; } } CaptureWindow = GetWindowFromPoint(e.FirstCapturedPoints.FirstOrDefault()); _recognizedApplication = GetApplicationFromWindow(CaptureWindow); int maxThreshold = 0, maxLimitNumber = 1; foreach (IApplication app in _recognizedApplication) { switch (app) { case GlobalApp a: maxLimitNumber = a.LimitNumberOfFingers > maxLimitNumber ? a.LimitNumberOfFingers : maxLimitNumber; if (AppConfig.IgnoreFullScreen && IsFullScreenWindow(e.FirstCapturedPoints.FirstOrDefault())) { e.Cancel = true; return; } break; case UserApp a: maxThreshold = a.BlockTouchInputThreshold > maxThreshold ? a.BlockTouchInputThreshold : maxThreshold; maxLimitNumber = a.LimitNumberOfFingers > maxLimitNumber ? a.LimitNumberOfFingers : maxLimitNumber; break; case IgnoredApp a: if (a.IsEnabled) { e.Cancel = true; return; } break; default: return; } } e.Cancel = (pointCapture.SourceDevice & Devices.TouchDevice) != 0 && (e.Points.Count < maxLimitNumber); e.BlockTouchInputThreshold = maxThreshold; }
private void mouseHook_MouseMove(object sender, MouseEventArgs e) { if (shouldClose) { return; } Rectangle screen = Screen.PrimaryScreen.Bounds; Point pt = Cursor.Position; int left = pt.X > screen.Width / 2 ? 20 : screen.Width - this.Width - 20; int top = pt.Y > screen.Height / 2 ? 20 : screen.Height - this.Height - 20; if (left != Left || top != Top) { Location = new Point(left, top); Focus(); } if (extraPointIndex != -1 || pt == highlightedPoint) { return; } highlightedPoint = pt; if (selectAccObjects) { SystemAccessibleObject acc = SystemAccessibleObject.FromPoint(pt.X, pt.Y); Highlight(acc.Window, acc); } else { SystemWindow sw = SystemWindow.FromPointEx(pt.X, pt.Y, false, false); Highlight(sw, null); freshWindow = true; } }
void HandleDown(ContactInfo contact) { State windowState; Point transformedCoordinates; SystemWindow window = GetWindowFromContact(contact, out windowState, out transformedCoordinates); if (window == null) { window = SystemWindow.FromPointEx((int)contact.Center.X, (int)contact.Center.Y, true, true); } if (window != null) { State state; if (windowTable.ContainsKey(window)) { state = windowTable[window]; } else { state = new State(window, contact.Id); state.LastPoint = contact.Center; windowTable.Add(window, state); } if (state.FirstContactId == -1) { state.FirstContactId = contact.Id; } state.ContactCount++; } }
protected void PointCapture_CaptureStarted(object sender, PointsCapturedEventArgs e) { var pointCapture = (IPointCapture)sender; if (pointCapture.Mode == CaptureMode.Training) { return; } if (Environment.OSVersion.Version.Major == 6) { IntPtr hwndCharmBar = FindWindow("NativeHWNDHost", "Charm Bar"); var window = SystemWindow.FromPointEx(SystemWindow.DesktopWindow.Rectangle.Right - 1, 1, true, true); if (window != null && window.HWnd.Equals(hwndCharmBar)) { e.Cancel = false; e.BlockTouchInputThreshold = 0; return; } } CaptureWindow = GetWindowFromPoint(e.FirstCapturedPoints.FirstOrDefault()); _recognizedApplication = GetApplicationFromWindow(CaptureWindow); int maxThreshold = 0; bool?limitNumberFlag = null; foreach (IApplication app in _recognizedApplication) { var userApplication = app as UserApp; if (userApplication != null) { maxThreshold = userApplication.BlockTouchInputThreshold > maxThreshold ? userApplication.BlockTouchInputThreshold : maxThreshold; //Got UserApplication if (limitNumberFlag == null) { limitNumberFlag = e.Points.Count < userApplication.LimitNumberOfFingers; } else { limitNumberFlag |= e.Points.Count < userApplication.LimitNumberOfFingers; } } else { var ignoredApplication = app as IgnoredApp; if (ignoredApplication != null && ignoredApplication.IsEnabled) { e.Cancel = true; return; } } } e.Cancel = pointCapture.SourceDevice == Device.Touch && (limitNumberFlag ?? e.Points.Count == 1); e.BlockTouchInputThreshold = maxThreshold; }
protected void chCrosshair_CrosshairDragging(object sender, EventArgs e) { Point cursorPosition = Cursor.Position; SystemWindow window = SystemWindow.FromPointEx(cursorPosition.X, cursorPosition.Y, true, true); // Set MatchUsings MatchUsing muRunning = ((MatchUsingComboBoxItem)cmbMatchUsingRunning.SelectedItem).MatchUsing; MatchUsing muCustom = ((MatchUsingComboBoxItem)cmbMatchUsingCustom.SelectedItem).MatchUsing; alvRunningApplications.MatchUsing = muRunning; // Which screen are we changing if (SelectedTab == TabType.Running) // Running applications { switch (muRunning) { case MatchUsing.WindowClass: alvRunningApplications.SelectSimilar(window.ClassName); break; case MatchUsing.WindowTitle: alvRunningApplications.SelectSimilar(window.Title); break; case MatchUsing.ExecutableFilename: alvRunningApplications.SelectSimilar(Path.GetFileName(window.Process.MainModule.FileName)); break; } } else // Custom Application { switch (muCustom) { case MatchUsing.WindowClass: txtMatchString.Text = window.ClassName; break; case MatchUsing.WindowTitle: txtMatchString.Text = window.Title; break; case MatchUsing.ExecutableFilename: txtMatchString.Text = window.Process.MainModule.FileName; txtMatchString.SelectionStart = txtMatchString.Text.Length; break; } // Set application name from filename txtApplicationName.Text = window.Process.MainModule.FileVersionInfo.FileDescription; } }
private SystemWindow GetTargetWindow() { Point cursorPosition; //(e.OriginalSource as Image).PointToScreen(e.GetPosition(null)); GetCursorPos(out cursorPosition); SystemWindow window = SystemWindow.FromPointEx(cursorPosition.X, cursorPosition.Y, true, true); return(window); }
SystemWindow GetWindowFromContact(ContactInfo contact, out State windowState, out Point transformedScreenCoordinates) { SystemWindow window = null; transformedScreenCoordinates = new Point(); windowState = null; List <SystemWindow> toDelete = new List <SystemWindow>(); foreach (var valuePair in windowTable) { SystemWindow currentWindow = valuePair.Key; if (currentWindow.Process.Id.Equals(0)) { toDelete.Add(currentWindow); continue; } Point windowCoordinates = ScreenToClient(currentWindow, contact.Center); windowState = valuePair.Value; Matrix m = windowState.GetMatrix(currentWindow); m.Invert(); Point transformedPoint = m.Transform(windowCoordinates); transformedScreenCoordinates = ClientToScreen(currentWindow, transformedPoint); SystemWindow windowFromPoint = SystemWindow.FromPointEx((int)transformedScreenCoordinates.X, (int)transformedScreenCoordinates.Y, true, true); if (windowFromPoint == currentWindow) { window = windowFromPoint; break; } } foreach (SystemWindow systemWindow in toDelete) { windowTable.Remove(systemWindow); } string msg; if (window == null) { msg = "window not found"; } else { msg = string.Format("WIN: {0}", window.ClassName); } Trace.WriteLine(string.Format("{0}", msg)); return(window); }
private void crosshair_CrosshairDragged(object sender, EventArgs e) { SystemWindow sw = SystemWindow.FromPointEx(Cursor.Position.X, Cursor.Position.Y, true, false); if (autoHide.Checked) { Visible = true; } if (sw == null) { return; } log.Text = ""; attributes.Clear(); controller.guessWindow(this, sw); controller.summarize(this, attributes.ToArray()); }
protected void TouchCapture_CaptureStarted(object sender, PointsCapturedEventArgs e) { var touchCapture = (ITouchCapture)sender; if (touchCapture.Mode == CaptureMode.Training) { return; } if (Environment.OSVersion.Version.Major == 6) { IntPtr hwndCharmBar = FindWindow("NativeHWNDHost", "Charm Bar"); var window = SystemWindow.FromPointEx(SystemWindow.DesktopWindow.Rectangle.Right - 1, 1, true, true); if (window != null && window.HWnd.Equals(hwndCharmBar)) { e.Cancel = e.InterceptTouchInput = false; return; } } CaptureWindow = GetWindowFromPoint(e.LastCapturedPoints.FirstOrDefault()); IApplication[] applicationFromWindow = GetApplicationFromWindow(CaptureWindow); foreach (IApplication app in applicationFromWindow) { e.InterceptTouchInput |= (app is UserApplication && (app as UserApplication).InterceptTouchInput); if ((app is IgnoredApplication) && (app as IgnoredApplication).IsEnabled) { e.Cancel = true; return; } else if (e.Points.Count == 1) { e.Cancel = true; UserApplication userApplication = app as UserApplication; if (userApplication != null && userApplication.AllowSingleStroke) { e.Cancel = false; return; } } } }
private void ChCrosshair_OnCrosshairDragging(object sender, MouseEventArgs e) { Point cursorPosition; //(e.OriginalSource as Image).PointToScreen(e.GetPosition(null)); GetCursorPos(out cursorPosition); SystemWindow window = SystemWindow.FromPointEx(cursorPosition.X, cursorPosition.Y, true, true); // Set MatchUsings MatchUsing muCustom = matchUsingRadio.MatchUsing; // Which screen are we changing try { switch (muCustom) { case MatchUsing.WindowClass: MatchStringTextBox.Text = window.ClassName; break; case MatchUsing.WindowTitle: MatchStringTextBox.Text = window.Title; break; case MatchUsing.ExecutableFilename: MatchStringTextBox.Text = window.Process.MainModule.ModuleName;//.FileName; MatchStringTextBox.SelectionStart = MatchStringTextBox.Text.Length; break; } // Set application name from filename ApplicationNameTextBox.Text = window.Process.MainModule.FileVersionInfo.FileDescription; } catch (Exception ex) { MatchStringTextBox.Text = LocalizationProvider.Instance.GetTextValue("Messages.Error") + ":" + ex.Message; } }
public IntPtr GetWindowAt(Point screenCoordinates, out Point transformedScreenCoordinates) { IntPtr result = IntPtr.Zero; transformedScreenCoordinates = screenCoordinates; foreach (Window currentWindow in windowToBody.Keys) { Matrix matrix = currentWindow.GetMatrix(currentWindow); matrix.Invert(); Point windowCoordinates = NativeMethods.ScreenToClient(currentWindow, screenCoordinates); System.Windows.Point transformedPoint = matrix.Transform(windowCoordinates.ToPoint()); transformedScreenCoordinates = NativeMethods.ClientToScreen(currentWindow, transformedPoint.ToPoint()); SystemWindow windowAtPoint = SystemWindow.FromPointEx(transformedScreenCoordinates.X, transformedScreenCoordinates.Y, true, true); if (windowAtPoint != null && windowAtPoint.HWnd.Equals(currentWindow.HWnd)) { result = windowAtPoint.HWnd; break; } } return(result); }
void HandleUp(ContactInfo contact) { State windowState; Point transformedCoordinates; SystemWindow window = GetWindowFromContact(contact, out windowState, out transformedCoordinates); if (window == null) { window = SystemWindow.FromPointEx((int)contact.Center.X, (int)contact.Center.Y, true, true); } if (window != null) { if (windowTable.ContainsKey(window)) { State state = windowTable[window]; state.ContactCount--; if (state.FirstContactId == contact.Id) { state.FirstContactId = -1; } } } }
public SystemWindow GetWindowFromPoint(Point point) { return(SystemWindow.FromPointEx(point.X, point.Y, true, true)); }
private void update(bool finished) { update(SystemWindow.FromPointEx(MousePosition.X, MousePosition.Y, false, false), finished); }
private void update() { update(SystemWindow.FromPointEx(MousePosition.X, MousePosition.Y, false, false)); }
bool HandleMove(ContactInfo contact, ContactInfo[] allContacts) { State windowState; Point transformedCoordinates; SystemWindow window = GetWindowFromContact(contact, out windowState, out transformedCoordinates); if (window == null) { window = SystemWindow.FromPointEx((int)contact.Center.X, (int)contact.Center.Y, true, true); } if (window != null) { if (windowTable.ContainsKey(window)) { State state = windowTable[window]; if (state.ContactCount > 1 && window.WindowState != FormWindowState.Maximized) { if (state.FirstContactId == contact.Id) { //Rotate Point nullPoint = new Point( window.Rectangle.Left + (SystemInformation.HorizontalResizeBorderThickness + window.Rectangle.Width) / 2.0, window.Rectangle.Top + (SystemInformation.VerticalResizeBorderThickness + window.Rectangle.Height) / 2.0); Point currentPoint = contact.Center; Vector vector1 = state.LastPoint - nullPoint; Vector vector2 = currentPoint - nullPoint; double between = Vector.AngleBetween(vector1, vector2); state.Angle += between; state.LastPoint = currentPoint; } //rotate end //Scale /* IEnumerable<ContactInfo> movedContacts = allContacts.Where(x => x.State == ContactState.Move); * ContactInfo[] array = movedContacts.ToArray(); * double origDist = 0.0; * double curDist = 0.0; * int divisor = 0; * for (int i = 0; i < array.Length; i++) * { * for (int j = i + 1; j < array.Length; j++) * { * Vector vector = array[j].Center - array[i].Center; * Vector previousVector = array[j].PreviousCenter - array[i].PreviousCenter; * origDist += vector.Length; * curDist += previousVector.Length; * divisor++; * } * } * * origDist /= divisor; * curDist /= divisor; * * if (origDist == 0) * origDist = 1; * * state.LastScale += curDist / origDist - state.LastDistance; * if (Math.Abs(state.LastScale) > 0.001) * state.Scale = 1 * state.LastScale; * else * state.LastScale = 1; * * state.LastDistance = curDist / origDist; */ //scale end Matrix m = state.Matrix; if (!NativeMethods.InSendMessage()) { dwm.SetWindowMatrix2(window.HWnd.ToInt32(), (float)m.M11, (float)m.M12, (float)m.M21, (float)m.M22, (float)m.OffsetX, (float)m.OffsetY); } else { lock (tasks) { tasks.Enqueue(() => { if (window != null) { dwm.SetWindowMatrix2(window.HWnd.ToInt32(), (float)m.M11, (float)m.M12, (float)m.M21, (float)m.M22, (float)m.OffsetX, (float)m.OffsetY); } }); } } return(true); } } } return(false); }
private void tmrUpdate_Tick(object sender, EventArgs e) { int shiftState = shiftKey.AsyncState; int altState = altKey.AsyncState; int ctrlState = ctrlKey.AsyncState; if (menuMode != 0) { switch (menuMode) { case 1: // in menu { if (ctrlState >= 0) { menuMode = 0; menuPanel.Visible = false; } else if (shiftState < 0) { InvokeMenu(menuIndex); return; } else { if (MousePosition.X / 5 > lastX && menuIndex % 3 != 2) { menuIndex++; } if (MousePosition.X / 5 < lastX && menuIndex % 3 != 0) { menuIndex--; } if (MousePosition.Y / 5 > lastY && menuIndex < 6) { menuIndex += 3; } if (MousePosition.Y / 5 < lastY && menuIndex >= 3) { menuIndex -= 3; } menuButtons[menuIndex].Select(); } lastX = MousePosition.X / 5; lastY = MousePosition.Y / 5; } break; case 2: // move/resize if (shiftState >= 0) { infoPanel.Visible = false; menuMode = 1; lastX = MousePosition.X / 5; lastY = MousePosition.Y / 5; } else { Rectangle r = windowData.Window.Position.ToRectangle(); if (menuIndex == 0) { r.Location = new Point(MousePosition.X + lastX, MousePosition.Y + lastY); } else { r.Size = new Size(MousePosition.X + lastX, MousePosition.Y + lastY); } windowData.Window.Position = RECT.FromRectangle(r); } break; case 3: // select if (shiftState >= 0) { if (menuListBox.Focused && menuListBox.Items.Count > 0) { switch (menuIndex) { case 1: // Toggle enabled windowData.Window.Enabled = menuListBox.SelectedIndex == 0; break; case 2: // Toggle visible windowData.Window.VisibilityFlag = menuListBox.SelectedIndex == 0; break; case 3: // Select Parent or Ancestor goto case 5; case 5: // Select Child SystemWindow sw = (SystemWindow)menuListBox.SelectedItem; if (sw != null) { UpdateProperties(sw); } break; case 6: // Advanced // unused break; } } listPanel.Visible = false; menuMode = 1; } else { if (menuListBox.Focused && menuListBox.Items.Count > 0) { if (MousePosition.Y / 5 > lastY) { menuListBox.SelectedIndex = (menuListBox.SelectedIndex + 1) % menuListBox.Items.Count; } if (MousePosition.Y / 5 < lastY) { menuListBox.SelectedIndex = (menuListBox.SelectedIndex + menuListBox.Items.Count) % menuListBox.Items.Count; } } if (MousePosition.X / 5 > lastX) { menuListBox.Focus(); } if (MousePosition.X / 5 < lastX) { menuCancel.Focus(); } } lastX = MousePosition.X / 5; lastY = MousePosition.Y / 5; break; case 4: // Change/Scroll Tab if (shiftState >= 0) { menuPanel.Visible = true; menuMode = 1; } else { if (tabs.SelectedIndex <= 1) { TextBox tb = tabs.SelectedIndex == 1 ? parentProperties : windowProperties; if (MousePosition.Y / 5 > lastY) { int pos = tb.SelectionStart; pos = tb.Text.IndexOf('\n', pos); if (pos == -1) { tb.Select(tb.Text.Length, 0); } else { tb.Select(pos + 1, 0); } tb.ScrollToCaret(); } if (MousePosition.Y / 5 < lastY) { int pos = tb.SelectionStart; pos = tb.Text.LastIndexOf("\n", pos); if (pos == -1) { tb.Select(0, 0); } else { tb.Select(pos - 2, 0); } tb.ScrollToCaret(); } } if (MousePosition.X / 5 > lastX) { tabs.SelectedIndex = 1; } if (MousePosition.X / 5 < lastX) { tabs.SelectedIndex = 0; } } lastX = MousePosition.X / 5; lastY = MousePosition.Y / 5; break; default: break; } return; } if (ctrlMenu.Checked && ctrlState < 0) { menuPanel.Visible = true; menuMode = 1; menuIndex = 4; menuButtons[4].Select(); lastX = MousePosition.X / 5; lastY = MousePosition.Y / 5; Text = "Window Information (Menu)"; return; } if (altState < 0 && altToggleTab.Checked) { altToggle = true; tabs.SelectedIndex = 1; } else if (altToggle) { altToggle = false; tabs.SelectedIndex = 0; } if (MousePosition.X != lastX || MousePosition.Y != lastY) { delaycount = 50; delay.Text = "Delay"; lastX = MousePosition.X; lastY = MousePosition.Y; if (avoidMouse.Checked && shiftState >= 0) { if (lastX >= Left && lastY >= Top && lastX <= Left + Width && lastY <= Top + Height) { Screen cs = Screen.FromPoint(Location); int ll = cs.WorkingArea.Width - (Left + Width - cs.WorkingArea.X) + cs.WorkingArea.X; int tt = cs.WorkingArea.Height - (Top + Height - cs.WorkingArea.Y) + cs.WorkingArea.Y; Location = new Point(ll, tt); if (lastX >= Left && lastY >= Top && lastX <= Left + Width && lastY <= Top + Height) { Location = new Point(5, 5); } } } SystemWindow sw = SystemWindow.FromPointEx(lastX, lastY, false, false); UpdateProperties(sw); if (tabs.SelectedIndex == 1) { this.Text = "Window Information (Relative: " + (lastX - copiedX) + "," + (lastY - copiedY) + ")"; } else { this.Text = "Window Information (Mouse: " + lastX + "," + lastY + ")"; } } else { if (delaycount > 0) { delaycount--; if (delaycount < 40) { delay.Text = "" + delaycount / 10; } if (delaycount < 10) { delaycount = -1; if (delayedUpdate.Checked) { windowProperties.Text = delayedProperties; parentProperties.Text = delayedMainProperties; } if (autoCopy.Checked) { copied.Items.Insert(1, new CopiedWindow(windowData, windowProperties.Text, parentData, parentProperties.Text)); delay.Text = "Copied"; } else { delay.Text = "Delay"; } } } } }
public SystemWindow GetWindowFromPoint(PointF Point) { return(SystemWindow.FromPointEx((int)Math.Floor(Point.X), (int)Math.Floor(Point.Y), true, true)); }