Win32Api.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace GUI
  4. {
  5. public class Win32Api
  6. {
  7. public const int WM_KEYDOWN = 0x100;
  8. public const int WM_KEYUP = 0x101;
  9. public const int WM_SYSKEYDOWN = 0x104;
  10. public const int WM_SYSKEYUP = 0x105;
  11. public const int WH_KEYBOARD_LL = 13;
  12. public const int WH_MOUSE_LL = 14;
  13. public const int MOUSEEVENTF_LEFTDOWN = 0x0002;
  14. public const int MOUSEEVENTF_MOVE = 0x0001;
  15. public const int MOUSEEVENTF_LEFTUP = 0x0004;
  16. public const int MOUSEEVENTF_ABSOLUTE = 0x8000;
  17. public const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
  18. public const int MOUSEEVENTF_RIGHTUP = 0x0010;
  19. public const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;
  20. public const int MOUSEEVENTF_MIDDLEUP = 0x0040;
  21. [StructLayout(LayoutKind.Sequential)]
  22. public class KeyboardHookStruct
  23. {
  24. public int vkCode;
  25. public int scanCode;
  26. public int flags;
  27. public int time;
  28. public int dwExtraInfo;
  29. }
  30. [StructLayout(LayoutKind.Sequential)]
  31. public class POINT
  32. {
  33. public int x;
  34. public int y;
  35. }
  36. [StructLayout(LayoutKind.Sequential)]
  37. public class MouseHookStruct
  38. {
  39. public POINT pt;
  40. public int hwnd;
  41. public int wHitTestCode;
  42. public int dwExtraInfo;
  43. }
  44. public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);
  45. [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  46. public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
  47. [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  48. public static extern bool UnhookWindowsHookEx(int idHook);
  49. [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  50. public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);
  51. [DllImport("user32")]
  52. public static extern int ToAscii(int uVirtKey, int uScanCode, byte[] lpbKeyState, byte[] lpwTransKey, int fuState);
  53. [DllImport("user32")]
  54. public static extern int GetKeyboardState(byte[] pbKeyState);
  55. [DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  56. public static extern IntPtr GetModuleHandle(string lpModuleName);
  57. [DllImport("kernel32.dll")]
  58. public static extern void AllocConsole();
  59. [DllImport("user32")]
  60. public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
  61. }
  62. }