99 lines
3.0 KiB
C#
99 lines
3.0 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Recordingtest.Recorder;
|
|
|
|
internal static class NativeMethods
|
|
{
|
|
public const int WH_KEYBOARD_LL = 13;
|
|
public const int WH_MOUSE_LL = 14;
|
|
|
|
public const int WM_KEYDOWN = 0x0100;
|
|
public const int WM_KEYUP = 0x0101;
|
|
public const int WM_SYSKEYDOWN = 0x0104;
|
|
public const int WM_SYSKEYUP = 0x0105;
|
|
|
|
public const int WM_LBUTTONDOWN = 0x0201;
|
|
public const int WM_LBUTTONUP = 0x0202;
|
|
public const int WM_RBUTTONDOWN = 0x0204;
|
|
public const int WM_RBUTTONUP = 0x0205;
|
|
public const int WM_MBUTTONDOWN = 0x0207;
|
|
public const int WM_MBUTTONUP = 0x0208;
|
|
public const int WM_MOUSEWHEEL = 0x020A;
|
|
public const int WM_MOUSEMOVE = 0x0200;
|
|
|
|
public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct POINT
|
|
{
|
|
public int x;
|
|
public int y;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct MSLLHOOKSTRUCT
|
|
{
|
|
public POINT pt;
|
|
public uint mouseData;
|
|
public uint flags;
|
|
public uint time;
|
|
public IntPtr dwExtraInfo;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct KBDLLHOOKSTRUCT
|
|
{
|
|
public uint vkCode;
|
|
public uint scanCode;
|
|
public uint flags;
|
|
public uint time;
|
|
public IntPtr dwExtraInfo;
|
|
}
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
public static extern IntPtr GetModuleHandle(string? lpModuleName);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern int GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern bool TranslateMessage(ref MSG lpMsg);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern IntPtr DispatchMessage(ref MSG lpMsg);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern void PostQuitMessage(int nExitCode);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern IntPtr WindowFromPoint(POINT pt);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern IntPtr GetForegroundWindow();
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct MSG
|
|
{
|
|
public IntPtr hwnd;
|
|
public uint message;
|
|
public IntPtr wParam;
|
|
public IntPtr lParam;
|
|
public uint time;
|
|
public POINT pt;
|
|
}
|
|
}
|