Beispiel #1
0
        public Win32Point GetUnityWindowCenter()
        {
            Win32Rect rect;

            User32interop.GetWindowRect(_unityHWnd, out rect);
            return(new Win32Point((rect.left + rect.right) / 2, (rect.bottom + rect.top) / 2));
        }
Beispiel #2
0
        public Vector2 GetGlobalCursorPos()
        {
            Win32Point pos;

            User32interop.GetCursorPos(out pos);
            return(new Vector2(pos.X, pos.Y));
        }
        private static string GetClassNameOfWindow(IntPtr hwnd)
        {
            int           clsMaxLength = 1000;
            StringBuilder classText    = new StringBuilder("", clsMaxLength + 5);

            User32interop.GetClassName(hwnd, classText, clsMaxLength + 2);

            if (!String.IsNullOrEmpty(classText.ToString()) && !String.IsNullOrEmpty(classText.ToString()))
            {
                return(classText.ToString());
            }

            return(string.Empty);
        }
        /// <summary>
        /// Gets the hwnd of the Unity Game Window.
        /// </summary>
        /// <returns>The Unity Game Window hwnd</returns>
        public static IntPtr GetUnityWindowHandle()
        {
            IntPtr windowHandle = new IntPtr(0);

            do
            {
                windowHandle = User32interop.FindWindowEx(new IntPtr(0), windowHandle, null, null);
                string name = GetClassNameOfWindow(windowHandle);
                if (name.Equals("UnityWndClass"))
                {
                    break;
                }
            } while (windowHandle != IntPtr.Zero);
            return(windowHandle);
        }
Beispiel #5
0
        private bool GetLockKeyUp()
        {
            bool up    = false;
            int  state = User32interop.GetKeyState(VirtualKeyCodes.VK_F8);

            if (state < -1 && _priorLockKeyState > -1)
            {
                //down
            }
            else if (state > -1 && _priorLockKeyState < -1)
            {
                //up
                up = true;
            }
            _priorLockKeyState = state;
            return(up);
        }
Beispiel #6
0
 public void SetUnityWindowForeground()
 {
     User32interop.SetActiveWindow(_unityHWnd);
 }
Beispiel #7
0
 public WindowsUnityWindow()
 {
     _unityHWnd = User32interop.GetForegroundWindow();
 }
Beispiel #8
0
 public void SetGlobalCursorPos(Vector2 pos)
 {
     User32interop.SetCursorPos((int)pos.x, (int)pos.y);
 }