protected virtual void Update() { Cursor.visible = false; if (Input.GetKey(KeyCode.Mouse0)) { focused = true; } if (focused) { SetCursorPos(0, 0); unsafe { WinRect rect = new WinRect(); var window = GetActiveWindow(); GetWindowRect(window, new IntPtr(&rect)); SetCursorPos((rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2); } } // There *might* be an obvious lag of cursor. // Obvious in Editor but not obvious in build if hide the cursor. // Keep it stay. Keep it good. this.gameObject.transform.position = VirtualCursor.position; }
public static Rect UnityWindowPosition() { var process = System.Diagnostics.Process.GetProcessesByName("Unity"); var unitywinrect = new WinRect(); GetWindowRect(process[0].MainWindowHandle, ref unitywinrect); return(new Rect(0, 0, 1900, 1600)); }
/** * <summary>Get the rectangle of either standalone game window (game running as .exe), or the game window in Unity editor</summary> * <returns>Game window rectangle</returns> * */ public static Rect GetWindowRect() { WinRect rect = new WinRect(); IntPtr gameHwnd = Application.isEditor ? GetUnityWindowHandle() : GetGameWindowHandle(); GetWindowRect(gameHwnd, ref rect); return(new Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top)); }
/** * <summary>Get the position of either standalone game window (game running as .exe), or the game window in Unity editor</summary> * <returns>Game window position</returns> * */ public static Vector2 GetWindowPosition() { WinRect rect = new WinRect(); GetWindowRect(GetUnityWindowHandle(), ref rect); return(new Vector2(rect.left, rect.top)); }
private static MyRectInWin _unityWin; // 当前Unity窗口的Rect(Windows坐标系) static MouseSimulater() { _temp = new WinRect(); _desktopWin = new MyRectInWin(); _unityWin = new MyRectInWin(); RefreshWin(); RefreshUnityWin(); Cursor.visible = true; }
public void UpdateRect(WinRect winRect) { _left = winRect.Left; _right = winRect.Right; _bottom = winRect.Bottom; _top = winRect.Top; _weight = _right - _left; _height = _bottom - _top; _leftBottom = new Vector2(_left, _bottom); }
private void chkRegion_CheckedChanged(object sender, EventArgs e) { btnRegion.Enabled = chkRegion.Checked; if (chkRegion.Checked && WinRect != Rectangle.Empty) { txtMouseSubregion.Text = WinRect.ToString(); } else { txtMouseSubregion.Text = "No subregion selected."; } }
// // Static methods // #region Static methods // Get desktop resolution public static ResolutionInfo GetResolution() { IntPtr desktop_hwnd = GetWindowRectWrapper.GetDesktopWindow(); var desktop_rect = new WinRect(); if (!GetWindowRectWrapper.GetWindowRectangle(desktop_hwnd, ref desktop_rect)) { return(new ResolutionInfo()); } else { return(new ResolutionInfo(desktop_rect)); } }
private void btnRegion_Click(object sender, EventArgs e) { //mouse REGION DialogResult res; if (string.IsNullOrEmpty(cmbProcessMouse.Text.Trim()) || cmbProcessMouse.Text.Equals("<any>", StringComparison.OrdinalIgnoreCase)) { res = wm.ShowDialog(null, WinRect); } else { res = wm.ShowDialog(cmbProcessMouse.Text.Split('|'), _clearOffset ? Rectangle.Empty : WinRect); } if (res == DialogResult.OK) { WinRect = wm.GetRect(); txtMouseSubregion.Text = WinRect.ToString(); } _clearOffset = false; }
private static extern bool GetWindowRect(IntPtr hwnd, out WinRect lpRect);
private static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out WinRect pvAttribute, int cbAttribute);
public static extern bool GetWindowRect(IntPtr hwnd, out WinRect lpRect);
internal static extern bool GetWindowRect(IntPtr hWnd, out WinRect lpRect);
private static extern bool GetWindowRect(IntPtr hWnd, ref WinRect winRect); // 获取窗口的Rect
private static extern bool GetWindowRect(IntPtr hwnd, ref WinRect rect);
public static extern bool GetWindowRect(System.IntPtr hwnd, ref WinRect rectangle);
[DllImport("user32.dll")] private static extern bool GetWindowRect(IntPtr hwnd, out WinRect lpRect);
// Constructor - From Windows RECT structure public ResolutionInfo(WinRect pRect) { mHeight = pRect.mBottom; mWidth = pRect.mRight; }