Created
June 6, 2020 09:13
-
-
Save kusa-mochi/0631ef663c1af16b7c55b2cf7e5113d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
namespace KusaMochiAutoLibrary.NativeFunctions | |
{ | |
[StructLayout(LayoutKind.Sequential)] | |
public struct Win32Point | |
{ | |
public Int32 X; | |
public Int32 Y; | |
}; | |
[StructLayout(LayoutKind.Sequential)] | |
internal struct MSLLHOOKSTRUCT | |
{ | |
internal Win32Point pt; | |
internal int mouseData; | |
internal int flags; | |
internal int time; | |
internal IntPtr dwExtraInfo; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
internal struct KBDLLHOOKSTRUCT | |
{ | |
internal int vkCode; | |
internal int scanCode; | |
internal int flags; | |
internal int time; | |
internal IntPtr dwExtraInfo; | |
}; | |
internal static class NativeMethods | |
{ | |
internal const int MOUSEEVENTF_MOVE = 0x1; | |
internal const int MOUSEEVENTF_ABSOLUTE = 0x8000; | |
internal const int MOUSEEVENTF_LEFTDOWN = 0x2; | |
internal const int MOUSEEVENTF_LEFTUP = 0x4; | |
internal const int MOUSEEVENTF_RIGHTDOWN = 0x8; | |
internal const int MOUSEEVENTF_RIGHTUP = 0x10; | |
internal const int MOUSEEVENTF_MIDDLEDOWN = 0x20; | |
internal const int MOUSEEVENTF_MIDDLEUP = 0x40; | |
internal const int MOUSEEVENTF_WHEEL = 0x800; | |
internal const int WHEEL_DELTA = 120; | |
internal const int KEYEVENTF_KEYDOWN = 0x0; | |
internal const int KEYEVENTF_KEYUP = 0x2; | |
internal const int KEYEVENTF_EXTENDEDKEY = 0x1; | |
internal enum HookType | |
{ | |
WH_KEYBOARD_LL = 13, | |
WH_MOUSE_LL = 14 | |
} | |
internal enum MouseMessage | |
{ | |
WM_LBUTTONDOWN = 0x0201, | |
WM_LBUTTONUP = 0x0202, | |
WM_MOUSEMOVE = 0x0200, | |
WM_MOUSEWHEEL = 0x020A, | |
WM_RBUTTONDOWN = 0x0204, | |
WM_RBUTTONUP = 0x0205, | |
WM_MBUTTONDOWN = 0x0207, | |
WM_MBUTTONUP = 0x0208 | |
} | |
internal enum KeyboardMessage | |
{ | |
WM_KEYDOWN = 0x0100, | |
WM_KEYUP = 0x0101, | |
WM_SYSKEYDOWN = 0x0104, | |
WM_SYSKEYUP = 0x0105 | |
} | |
internal delegate IntPtr LowLevelMouseKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); | |
#region user32.dll | |
[DllImport("user32.dll")] | |
internal static extern bool GetCursorPos(ref Win32Point pt); | |
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
internal static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); | |
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
internal static extern bool UnhookWindowsHookEx(IntPtr hhk); | |
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
internal static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); | |
#endregion | |
#region kernel32.dll | |
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
internal static extern IntPtr GetModuleHandle(string lpModuleName); | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment