MouseUtil.cs 865 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. namespace GeekDesk.Util
  9. {
  10. class MouseUtil
  11. {
  12. [DllImport("user32.dll")]
  13. [return: MarshalAs(UnmanagedType.Bool)]
  14. internal static extern bool GetCursorPos(ref Win32Point pt);
  15. [StructLayout(LayoutKind.Sequential)]
  16. internal struct Win32Point
  17. {
  18. public Int32 X;
  19. public Int32 Y;
  20. };
  21. /// <summary>
  22. /// 获取鼠标坐标
  23. /// </summary>
  24. /// <returns></returns>
  25. public static Point GetMousePosition()
  26. {
  27. var w32Mouse = new Win32Point();
  28. GetCursorPos(ref w32Mouse);
  29. return new Point(w32Mouse.X, w32Mouse.Y);
  30. }
  31. }
  32. }