You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.4 KiB

  1. // This code is distributed under MIT license.
  2. // Copyright (c) 2015 George Mamaladze
  3. // See license.txt or https://mit-license.org/
  4. using System;
  5. using System.Runtime.InteropServices;
  6. namespace Gma.System.MouseKeyHook.WinApi
  7. {
  8. /// <summary>
  9. /// The AppMouseStruct structure contains information about a application-level mouse input event.
  10. /// </summary>
  11. /// <remarks>
  12. /// See full documentation at http://globalmousekeyhook.codeplex.com/wikipage?title=MouseStruct
  13. /// </remarks>
  14. [StructLayout(LayoutKind.Explicit)]
  15. internal struct AppMouseStruct
  16. {
  17. /// <summary>
  18. /// Specifies a Point structure that contains the X- and Y-coordinates of the cursor, in screen coordinates.
  19. /// </summary>
  20. [FieldOffset(0x00)] public Point Point;
  21. /// <summary>
  22. /// Specifies information associated with the message.
  23. /// </summary>
  24. /// <remarks>
  25. /// The possible values are:
  26. /// <list type="bullet">
  27. /// <item>
  28. /// <description>0 - No Information</description>
  29. /// </item>
  30. /// <item>
  31. /// <description>1 - X-Button1 Click</description>
  32. /// </item>
  33. /// <item>
  34. /// <description>2 - X-Button2 Click</description>
  35. /// </item>
  36. /// <item>
  37. /// <description>120 - Mouse Scroll Away from User</description>
  38. /// </item>
  39. /// <item>
  40. /// <description>-120 - Mouse Scroll Toward User</description>
  41. /// </item>
  42. /// </list>
  43. /// </remarks>
  44. [FieldOffset(0x16)] public short MouseData_x86;
  45. [FieldOffset(0x22)] public short MouseData_x64;
  46. /// <summary>
  47. /// Converts the current <see cref="AppMouseStruct" /> into a <see cref="MouseStruct" />.
  48. /// </summary>
  49. /// <returns></returns>
  50. /// <remarks>
  51. /// The AppMouseStruct does not have a timestamp, thus one is generated at the time of this call.
  52. /// </remarks>
  53. public MouseStruct ToMouseStruct()
  54. {
  55. var tmp = new MouseStruct();
  56. tmp.Point = Point;
  57. tmp.MouseData = IntPtr.Size == 4 ? MouseData_x86 : MouseData_x64;
  58. tmp.Timestamp = Environment.TickCount;
  59. return tmp;
  60. }
  61. }
  62. }