using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace linker.libs.winapis;
public static class User32
{
#region Constants
public const int CURSOR_SHOWING = 0x00000001;
public const Int32 DI_NORMAL = 0x0003;
public const uint MOUSEEVENTF_ABSOLUTE = 0x8000;
public const int MOUSEEVENTF_LEFTDOWN = 0x02;
public const int MOUSEEVENTF_LEFTUP = 0x04;
public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
public const int MOUSEEVENTF_RIGHTUP = 0x10;
public const int MOUSEEVENTF_MOVE = 0x0001;
public const int KEYEVENTF_KEYDOWN = 0x0000;
public const uint KEYEVENTF_EXTENDEDKEY = 0x0001;
public const uint KEYEVENTF_KEYUP = 0x0002;
public const int SPIF_SENDWININICHANGE = 0x02;
public const int SPI_SETDESKWALLPAPER = 20;
public const int SPIF_UPDATEINIFILE = 1;
public const int SPIF_SENDCHANGE = 2;
public static readonly int SPI_GETDESKWALLPAPER = 0x73;
public static readonly int MAX_PATH = 260;
#endregion
#region Enums
[Flags]
public enum MouseEventFlags : uint
{
MOVE = 0x0001,
LEFTDOWN = 0x0002,
LEFTUP = 0x0004,
RIGHTDOWN = 0x0008,
RIGHTUP = 0x0010,
MIDDLEDOWN = 0x0020,
MIDDLEUP = 0x0040,
XDOWN = 0x0080,
XUP = 0x0100,
VIRTUALDESK = 0x4000,
ABSOLUTE = 0x8000,
WHEEL = 0x0800,
HWHEEL = 0x1000,
}
[Flags]
public enum MOUSEEVENTF : uint
{
ABSOLUTE = 0x8000,
HWHEEL = 0x01000,
MOVE = 0x0001,
MOVE_NOCOALESCE = 0x2000,
LEFTDOWN = 0x0002,
LEFTUP = 0x0004,
RIGHTDOWN = 0x0008,
RIGHTUP = 0x0010,
MIDDLEDOWN = 0x0020,
MIDDLEUP = 0x0040,
VIRTUALDESK = 0x4000,
WHEEL = 0x0800,
XDOWN = 0x0080,
XUP = 0x0100
}
public enum MonitorState
{
MonitorStateOn = -1,
MonitorStateOff = 2,
MonitorStateStandBy = 1
}
[Flags]
public enum KEYEVENTF : uint
{
EXTENDEDKEY = 0x0001,
KEYUP = 0x0002,
SCANCODE = 0x0008,
UNICODE = 0x0004
}
public enum VirtualKey : short
{
///
///Left mouse button
///
LBUTTON = 0x01,
///
///Right mouse button
///
RBUTTON = 0x02,
///
///Control-break processing
///
CANCEL = 0x03,
///
///Middle mouse button (three-button mouse)
///
MBUTTON = 0x04,
///
///Windows 2000/XP: X1 mouse button
///
XBUTTON1 = 0x05,
///
///Windows 2000/XP: X2 mouse button
///
XBUTTON2 = 0x06,
///
///BACKSPACE key
///
BACK = 0x08,
///
///TAB key
///
TAB = 0x09,
///
///CLEAR key
///
CLEAR = 0x0C,
///
///ENTER key
///
RETURN = 0x0D,
///
///SHIFT key
///
SHIFT = 0x10,
///
///CTRL key
///
CONTROL = 0x11,
///
///ALT key
///
MENU = 0x12,
///
///PAUSE key
///
PAUSE = 0x13,
///
///CAPS LOCK key
///
CAPITAL = 0x14,
///
///Input Method Editor (IME) Kana mode
///
KANA = 0x15,
///
///IME Hangul mode
///
HANGUL = 0x15,
///
///IME Junja mode
///
JUNJA = 0x17,
///
///IME final mode
///
FINAL = 0x18,
///
///IME Hanja mode
///
HANJA = 0x19,
///
///IME Kanji mode
///
KANJI = 0x19,
///
///ESC key
///
ESCAPE = 0x1B,
///
///IME convert
///
CONVERT = 0x1C,
///
///IME nonconvert
///
NONCONVERT = 0x1D,
///
///IME accept
///
ACCEPT = 0x1E,
///
///IME mode change request
///
MODECHANGE = 0x1F,
///
///SPACEBAR
///
SPACE = 0x20,
///
///PAGE UP key
///
PRIOR = 0x21,
///
///PAGE DOWN key
///
NEXT = 0x22,
///
///END key
///
END = 0x23,
///
///HOME key
///
HOME = 0x24,
///
///LEFT ARROW key
///
LEFT = 0x25,
///
///UP ARROW key
///
UP = 0x26,
///
///RIGHT ARROW key
///
RIGHT = 0x27,
///
///DOWN ARROW key
///
DOWN = 0x28,
///
///SELECT key
///
SELECT = 0x29,
///
///PRINT key
///
PRINT = 0x2A,
///
///EXECUTE key
///
EXECUTE = 0x2B,
///
///PRINT SCREEN key
///
SNAPSHOT = 0x2C,
///
///INS key
///
INSERT = 0x2D,
///
///DEL key
///
DELETE = 0x2E,
///
///HELP key
///
HELP = 0x2F,
///
///0 key
///
KEY_0 = 0x30,
///
///1 key
///
KEY_1 = 0x31,
///
///2 key
///
KEY_2 = 0x32,
///
///3 key
///
KEY_3 = 0x33,
///
///4 key
///
KEY_4 = 0x34,
///
///5 key
///
KEY_5 = 0x35,
///
///6 key
///
KEY_6 = 0x36,
///
///7 key
///
KEY_7 = 0x37,
///
///8 key
///
KEY_8 = 0x38,
///
///9 key
///
KEY_9 = 0x39,
///
///A key
///
KEY_A = 0x41,
///
///B key
///
KEY_B = 0x42,
///
///C key
///
KEY_C = 0x43,
///
///D key
///
KEY_D = 0x44,
///
///E key
///
KEY_E = 0x45,
///
///F key
///
KEY_F = 0x46,
///
///G key
///
KEY_G = 0x47,
///
///H key
///
KEY_H = 0x48,
///
///I key
///
KEY_I = 0x49,
///
///J key
///
KEY_J = 0x4A,
///
///K key
///
KEY_K = 0x4B,
///
///L key
///
KEY_L = 0x4C,
///
///M key
///
KEY_M = 0x4D,
///
///N key
///
KEY_N = 0x4E,
///
///O key
///
KEY_O = 0x4F,
///
///P key
///
KEY_P = 0x50,
///
///Q key
///
KEY_Q = 0x51,
///
///R key
///
KEY_R = 0x52,
///
///S key
///
KEY_S = 0x53,
///
///T key
///
KEY_T = 0x54,
///
///U key
///
KEY_U = 0x55,
///
///V key
///
KEY_V = 0x56,
///
///W key
///
KEY_W = 0x57,
///
///X key
///
KEY_X = 0x58,
///
///Y key
///
KEY_Y = 0x59,
///
///Z key
///
KEY_Z = 0x5A,
///
///Left Windows key (Microsoft Natural keyboard)
///
LWIN = 0x5B,
///
///Right Windows key (Natural keyboard)
///
RWIN = 0x5C,
///
///Applications key (Natural keyboard)
///
APPS = 0x5D,
///
///Computer Sleep key
///
SLEEP = 0x5F,
///
///Numeric keypad 0 key
///
NUMPAD0 = 0x60,
///
///Numeric keypad 1 key
///
NUMPAD1 = 0x61,
///
///Numeric keypad 2 key
///
NUMPAD2 = 0x62,
///
///Numeric keypad 3 key
///
NUMPAD3 = 0x63,
///
///Numeric keypad 4 key
///
NUMPAD4 = 0x64,
///
///Numeric keypad 5 key
///
NUMPAD5 = 0x65,
///
///Numeric keypad 6 key
///
NUMPAD6 = 0x66,
///
///Numeric keypad 7 key
///
NUMPAD7 = 0x67,
///
///Numeric keypad 8 key
///
NUMPAD8 = 0x68,
///
///Numeric keypad 9 key
///
NUMPAD9 = 0x69,
///
///Multiply key
///
MULTIPLY = 0x6A,
///
///Add key
///
ADD = 0x6B,
///
///Separator key
///
SEPARATOR = 0x6C,
///
///Subtract key
///
SUBTRACT = 0x6D,
///
///Decimal key
///
DECIMAL = 0x6E,
///
///Divide key
///
DIVIDE = 0x6F,
///
///F1 key
///
F1 = 0x70,
///
///F2 key
///
F2 = 0x71,
///
///F3 key
///
F3 = 0x72,
///
///F4 key
///
F4 = 0x73,
///
///F5 key
///
F5 = 0x74,
///
///F6 key
///
F6 = 0x75,
///
///F7 key
///
F7 = 0x76,
///
///F8 key
///
F8 = 0x77,
///
///F9 key
///
F9 = 0x78,
///
///F10 key
///
F10 = 0x79,
///
///F11 key
///
F11 = 0x7A,
///
///F12 key
///
F12 = 0x7B,
///
///F13 key
///
F13 = 0x7C,
///
///F14 key
///
F14 = 0x7D,
///
///F15 key
///
F15 = 0x7E,
///
///F16 key
///
F16 = 0x7F,
///
///F17 key
///
F17 = 0x80,
///
///F18 key
///
F18 = 0x81,
///
///F19 key
///
F19 = 0x82,
///
///F20 key
///
F20 = 0x83,
///
///F21 key
///
F21 = 0x84,
///
///F22 key, (PPC only) Key used to lock device.
///
F22 = 0x85,
///
///F23 key
///
F23 = 0x86,
///
///F24 key
///
F24 = 0x87,
///
///NUM LOCK key
///
NUMLOCK = 0x90,
///
///SCROLL LOCK key
///
SCROLL = 0x91,
///
///Left SHIFT key
///
LSHIFT = 0xA0,
///
///Right SHIFT key
///
RSHIFT = 0xA1,
///
///Left CONTROL key
///
LCONTROL = 0xA2,
///
///Right CONTROL key
///
RCONTROL = 0xA3,
///
///Left MENU key
///
LMENU = 0xA4,
///
///Right MENU key
///
RMENU = 0xA5,
///
///Windows 2000/XP: Browser Back key
///
BROWSER_BACK = 0xA6,
///
///Windows 2000/XP: Browser Forward key
///
BROWSER_FORWARD = 0xA7,
///
///Windows 2000/XP: Browser Refresh key
///
BROWSER_REFRESH = 0xA8,
///
///Windows 2000/XP: Browser Stop key
///
BROWSER_STOP = 0xA9,
///
///Windows 2000/XP: Browser Search key
///
BROWSER_SEARCH = 0xAA,
///
///Windows 2000/XP: Browser Favorites key
///
BROWSER_FAVORITES = 0xAB,
///
///Windows 2000/XP: Browser Start and Home key
///
BROWSER_HOME = 0xAC,
///
///Windows 2000/XP: Volume Mute key
///
VOLUME_MUTE = 0xAD,
///
///Windows 2000/XP: Volume Down key
///
VOLUME_DOWN = 0xAE,
///
///Windows 2000/XP: Volume Up key
///
VOLUME_UP = 0xAF,
///
///Windows 2000/XP: Next Track key
///
MEDIA_NEXT_TRACK = 0xB0,
///
///Windows 2000/XP: Previous Track key
///
MEDIA_PREV_TRACK = 0xB1,
///
///Windows 2000/XP: Stop Media key
///
MEDIA_STOP = 0xB2,
///
///Windows 2000/XP: Play/Pause Media key
///
MEDIA_PLAY_PAUSE = 0xB3,
///
///Windows 2000/XP: Start Mail key
///
LAUNCH_MAIL = 0xB4,
///
///Windows 2000/XP: Select Media key
///
LAUNCH_MEDIA_SELECT = 0xB5,
///
///Windows 2000/XP: Start Application 1 key
///
LAUNCH_APP1 = 0xB6,
///
///Windows 2000/XP: Start Application 2 key
///
LAUNCH_APP2 = 0xB7,
///
///Used for miscellaneous characters; it can vary by keyboard.
///
OEM_1 = 0xBA,
///
///Windows 2000/XP: For any country/region, the '+' key
///
OEM_PLUS = 0xBB,
///
///Windows 2000/XP: For any country/region, the ',' key
///
OEM_COMMA = 0xBC,
///
///Windows 2000/XP: For any country/region, the '-' key
///
OEM_MINUS = 0xBD,
///
///Windows 2000/XP: For any country/region, the '.' key
///
OEM_PERIOD = 0xBE,
///
///Used for miscellaneous characters; it can vary by keyboard.
///
OEM_2 = 0xBF,
///
///Used for miscellaneous characters; it can vary by keyboard.
///
OEM_3 = 0xC0,
///
///Used for miscellaneous characters; it can vary by keyboard.
///
OEM_4 = 0xDB,
///
///Used for miscellaneous characters; it can vary by keyboard.
///
OEM_5 = 0xDC,
///
///Used for miscellaneous characters; it can vary by keyboard.
///
OEM_6 = 0xDD,
///
///Used for miscellaneous characters; it can vary by keyboard.
///
OEM_7 = 0xDE,
///
///Used for miscellaneous characters; it can vary by keyboard.
///
OEM_8 = 0xDF,
///
///Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
///
OEM_102 = 0xE2,
///
///Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
///
PROCESSKEY = 0xE5,
///
///Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes.
///The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information,
///see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
///
PACKET = 0xE7,
///
///Attn key
///
ATTN = 0xF6,
///
///CrSel key
///
CRSEL = 0xF7,
///
///ExSel key
///
EXSEL = 0xF8,
///
///Erase EOF key
///
EREOF = 0xF9,
///
///Play key
///
PLAY = 0xFA,
///
///Zoom key
///
ZOOM = 0xFB,
///
///Reserved
///
NONAME = 0xFC,
///
///PA1 key
///
PA1 = 0xFD,
///
///Clear key
///
OEM_CLEAR = 0xFE
}
public enum ScanCodeShort : short
{
LBUTTON = 0,
RBUTTON = 0,
CANCEL = 70,
MBUTTON = 0,
XBUTTON1 = 0,
XBUTTON2 = 0,
BACK = 14,
TAB = 15,
CLEAR = 76,
RETURN = 28,
SHIFT = 42,
CONTROL = 29,
MENU = 56,
PAUSE = 0,
CAPITAL = 58,
KANA = 0,
HANGUL = 0,
JUNJA = 0,
FINAL = 0,
HANJA = 0,
KANJI = 0,
ESCAPE = 1,
CONVERT = 0,
NONCONVERT = 0,
ACCEPT = 0,
MODECHANGE = 0,
SPACE = 57,
PRIOR = 73,
NEXT = 81,
END = 79,
HOME = 71,
LEFT = 75,
UP = 72,
RIGHT = 77,
DOWN = 80,
SELECT = 0,
PRINT = 0,
EXECUTE = 0,
SNAPSHOT = 84,
INSERT = 82,
DELETE = 83,
HELP = 99,
KEY_0 = 11,
KEY_1 = 2,
KEY_2 = 3,
KEY_3 = 4,
KEY_4 = 5,
KEY_5 = 6,
KEY_6 = 7,
KEY_7 = 8,
KEY_8 = 9,
KEY_9 = 10,
KEY_A = 30,
KEY_B = 48,
KEY_C = 46,
KEY_D = 32,
KEY_E = 18,
KEY_F = 33,
KEY_G = 34,
KEY_H = 35,
KEY_I = 23,
KEY_J = 36,
KEY_K = 37,
KEY_L = 38,
KEY_M = 50,
KEY_N = 49,
KEY_O = 24,
KEY_P = 25,
KEY_Q = 16,
KEY_R = 19,
KEY_S = 31,
KEY_T = 20,
KEY_U = 22,
KEY_V = 47,
KEY_W = 17,
KEY_X = 45,
KEY_Y = 21,
KEY_Z = 44,
LWIN = 91,
RWIN = 92,
APPS = 93,
SLEEP = 95,
NUMPAD0 = 82,
NUMPAD1 = 79,
NUMPAD2 = 80,
NUMPAD3 = 81,
NUMPAD4 = 75,
NUMPAD5 = 76,
NUMPAD6 = 77,
NUMPAD7 = 71,
NUMPAD8 = 72,
NUMPAD9 = 73,
MULTIPLY = 55,
ADD = 78,
SEPARATOR = 0,
SUBTRACT = 74,
DECIMAL = 83,
DIVIDE = 53,
F1 = 59,
F2 = 60,
F3 = 61,
F4 = 62,
F5 = 63,
F6 = 64,
F7 = 65,
F8 = 66,
F9 = 67,
F10 = 68,
F11 = 87,
F12 = 88,
F13 = 100,
F14 = 101,
F15 = 102,
F16 = 103,
F17 = 104,
F18 = 105,
F19 = 106,
F20 = 107,
F21 = 108,
F22 = 109,
F23 = 110,
F24 = 118,
NUMLOCK = 69,
SCROLL = 70,
LSHIFT = 42,
RSHIFT = 54,
LCONTROL = 29,
RCONTROL = 29,
LMENU = 56,
RMENU = 56,
BROWSER_BACK = 106,
BROWSER_FORWARD = 105,
BROWSER_REFRESH = 103,
BROWSER_STOP = 104,
BROWSER_SEARCH = 101,
BROWSER_FAVORITES = 102,
BROWSER_HOME = 50,
VOLUME_MUTE = 32,
VOLUME_DOWN = 46,
VOLUME_UP = 48,
MEDIA_NEXT_TRACK = 25,
MEDIA_PREV_TRACK = 16,
MEDIA_STOP = 36,
MEDIA_PLAY_PAUSE = 34,
LAUNCH_MAIL = 108,
LAUNCH_MEDIA_SELECT = 109,
LAUNCH_APP1 = 107,
LAUNCH_APP2 = 33,
OEM_1 = 39,
OEM_PLUS = 13,
OEM_COMMA = 51,
OEM_MINUS = 12,
OEM_PERIOD = 52,
OEM_2 = 53,
OEM_3 = 41,
OEM_4 = 26,
OEM_5 = 43,
OEM_6 = 27,
OEM_7 = 40,
OEM_8 = 0,
OEM_102 = 86,
PROCESSKEY = 0,
PACKET = 0,
ATTN = 0,
CRSEL = 0,
EXSEL = 0,
EREOF = 93,
PLAY = 0,
ZOOM = 98,
NONAME = 0,
PA1 = 0,
OEM_CLEAR = 0,
}
[Flags]
public enum ACCESS_MASK : uint
{
DELETE = 0x00010000,
READ_CONTROL = 0x00020000,
WRITE_DAC = 0x00040000,
WRITE_OWNER = 0x00080000,
SYNCHRONIZE = 0x00100000,
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
STANDARD_RIGHTS_READ = 0x00020000,
STANDARD_RIGHTS_WRITE = 0x00020000,
STANDARD_RIGHTS_EXECUTE = 0x00020000,
STANDARD_RIGHTS_ALL = 0x001F0000,
SPECIFIC_RIGHTS_ALL = 0x0000FFFF,
ACCESS_SYSTEM_SECURITY = 0x01000000,
MAXIMUM_ALLOWED = 0x02000000,
GENERIC_READ = 0x80000000,
GENERIC_WRITE = 0x40000000,
GENERIC_EXECUTE = 0x20000000,
GENERIC_ALL = 0x10000000,
DESKTOP_READOBJECTS = 0x00000001,
DESKTOP_CREATEWINDOW = 0x00000002,
DESKTOP_CREATEMENU = 0x00000004,
DESKTOP_HOOKCONTROL = 0x00000008,
DESKTOP_JOURNALRECORD = 0x00000010,
DESKTOP_JOURNALPLAYBACK = 0x00000020,
DESKTOP_ENUMERATE = 0x00000040,
DESKTOP_WRITEOBJECTS = 0x00000080,
DESKTOP_SWITCHDESKTOP = 0x00000100,
WINSTA_ENUMDESKTOPS = 0x00000001,
WINSTA_READATTRIBUTES = 0x00000002,
WINSTA_ACCESSCLIPBOARD = 0x00000004,
WINSTA_CREATEDESKTOP = 0x00000008,
WINSTA_WRITEATTRIBUTES = 0x00000010,
WINSTA_ACCESSGLOBALATOMS = 0x00000020,
WINSTA_EXITWINDOWS = 0x00000040,
WINSTA_ENUMERATE = 0x00000100,
WINSTA_READSCREEN = 0x00000200,
WINSTA_ALL_ACCESS = 0x0000037F
}
public enum InputType : uint
{
MOUSE = 0,
KEYBOARD = 1,
HARDWARE = 2
}
public enum MessageBoxType : long
{
MB_ABORTRETRYIGNORE = 0x00000002L,
MB_CANCELTRYCONTINUE = 0x00000006L,
MB_HELP = 0x00004000L,
MB_OK = 0x00000000L,
MB_OKCANCEL = 0x00000001L,
MB_RETRYCANCEL = 0x00000005L,
MB_YESNO = 0x00000004L,
MB_YESNOCANCEL = 0x00000003L,
MB_ICONEXCLAMATION = 0x00000030L,
MB_ICONWARNING = 0x00000030L,
MB_ICONINFORMATION = 0x00000040L,
MB_ICONASTERISK = 0x00000040L,
MB_ICONQUESTION = 0x00000020L,
MB_ICONSTOP = 0x00000010L,
MB_ICONERROR = 0x00000010L,
MB_ICONHAND = 0x00000010L,
MB_DEFBUTTON1 = 0x00000000L,
MB_DEFBUTTON2 = 0x00000100L,
MB_DEFBUTTON3 = 0x00000200L,
MB_DEFBUTTON4 = 0x00000300L,
MB_APPLMODAL = 0x00000000L,
MB_SYSTEMMODAL = 0x00001000L,
MB_TASKMODAL = 0x00002000L,
MB_DEFAULT_DESKTOP_ONLY = 0x00020000L,
MB_RIGHT = 0x00080000L,
MB_RTLREADING = 0x00100000L,
MB_SETFOREGROUND = 0x00010000L,
MB_TOPMOST = 0x00040000L,
MB_SERVICE_NOTIFICATION = 0x00200000L
}
public enum MessageBoxResult : int
{
IDABORT = 3,
IDCANCEL = 2,
IDCONTINUE = 11,
IDIGNORE = 5,
IDNO = 7,
IDOK = 1,
IDRETRY = 4,
IDTRYAGAIN = 10,
IDYES = 6,
}
public enum SW
{
SW_HIDE = 0,
SW_SHOWNORMAL = 1,
SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_SHOWMAXIMIZED = 3,
SW_MAXIMIZE = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9,
SW_SHOWDEFAULT = 10,
SW_MAX = 10
}
public enum VkMapType : uint
{
MAPVK_VK_TO_VSC = 0,
MAPVK_VSC_TO_VK = 1,
MAPVK_VK_TO_CHAR = 2,
MAPVK_VSC_TO_VK_EX = 3,
MAPVK_VK_TO_VSC_EX = 4
}
#endregion
#region Structs
[StructLayout(LayoutKind.Sequential)]
public struct ICONINFO
{
public bool fIcon;
public int xHotspot;
public int yHotspot;
public nint hbmMask;
public nint hbmColor;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
public struct CursorInfo
{
public int cbSize;
public int flags;
public nint hCursor;
public POINT ptScreenPos;
}
[StructLayout(LayoutKind.Sequential)]
public struct INPUT
{
public InputType type;
public InputUnion U;
public static int Size
{
get { return Marshal.SizeOf(typeof(INPUT)); }
}
}
[StructLayout(LayoutKind.Sequential)]
public struct InputEx
{
public InputType type;
public InputUnionEx U;
public static int Size
{
get { return Marshal.SizeOf(typeof(InputEx)); }
}
}
[StructLayout(LayoutKind.Explicit)]
public struct InputUnion
{
[FieldOffset(0)]
public MOUSEINPUT mi;
[FieldOffset(0)]
public KEYBDINPUT ki;
[FieldOffset(0)]
public HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Explicit)]
public struct InputUnionEx
{
[FieldOffset(0)]
public MOUSEINPUT mi;
[FieldOffset(0)]
public KeybdInputEx ki;
[FieldOffset(0)]
public HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Sequential)]
public struct MOUSEINPUT
{
public int dx;
public int dy;
public int mouseData;
public MOUSEEVENTF dwFlags;
public uint time;
public nuint dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct KEYBDINPUT
{
public VirtualKey wVk;
public ScanCodeShort wScan;
public KEYEVENTF dwFlags;
public int time;
public nuint dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct KeybdInputEx
{
public ushort wVk;
public ushort wScan;
public KEYEVENTF dwFlags;
public int time;
public nuint dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct HARDWAREINPUT
{
public int uMsg;
public short wParamL;
public short wParamH;
}
#endregion
[StructLayout(LayoutKind.Sequential)]
public struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
[DllImport("user32.dll")]
public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
public const int DESKTOPVERTRES = 117;
public const int DESKTOPHORZRES = 118;
public const int SM_CXSCREEN = 0;
public const int SM_CYSCREEN = 1;
public const int SM_REMOTESESSION = 0x1000;
[DllImport("gdi32.dll", EntryPoint = "GetDeviceCaps", SetLastError = true)]
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int mVal);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr hWnd);
#region DLL Imports
[DllImport("user32.dll")]
public static extern bool GetCursorInfo(out CursorInfo pci);
[DllImport("user32.dll", SetLastError = false)]
public static extern nint GetDesktopWindow();
[DllImport("user32.dll")]
public static extern nint GetCursor();
[DllImport("user32.dll")]
public static extern nint CopyIcon(nint hIcon);
[DllImport("user32.dll")]
public static extern bool DrawIcon(nint hdc, int x, int y, nint hIcon);
[DllImport("user32.dll")]
public static extern bool GetIconInfo(nint hIcon, out ICONINFO piconinfo);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyHeight, int istepIfAniCur, IntPtr hbrFlickerFreeDraw, int diFlags);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void Mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, nuint dwExtraInfo);
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
[DllImport("user32.dll")]
public static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos(out System.Drawing.Point lpPoint);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetCursorPos(int x, int y);
[DllImport("user32.dll")]
public static extern nint SetCursor(nint hcursor);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern nint LoadImage(nint hinst, string lpszName, uint uType,
int cxDesired, int cyDesired, uint fuLoad);
[DllImport("user32.dll")]
public static extern nint CreateCursor(nint hInst, int xHotSpot, int yHotSpot,
int nWidth, int nHeight, byte[] pvANDPlane, byte[] pvXORPlane);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PrintWindow(nint hwnd, nint hDC, uint nFlags);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SwitchDesktop(nint hDesktop);
public delegate bool EnumDesktopsDelegate(string desktop, nint lParam);
[DllImport("user32.dll")]
public static extern bool EnumDesktopsA(nint hwinsta, EnumDesktopsDelegate lpEnumFunc, nint lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern nint OpenInputDesktop(uint dwFlags, bool fInherit, ACCESS_MASK dwDesiredAccess);
public delegate bool EnumWindowStationsDelegate(string windowsStation, nint lParam);
[DllImport("user32.dll")]
public static extern bool EnumWindowStations(EnumWindowStationsDelegate lpEnumFunc, nint lParam);
[DllImport("user32.dll")]
public static extern nint GetShellWindow();
public sealed class SafeWindowStationHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public SafeWindowStationHandle()
: base(true)
{
}
protected override bool ReleaseHandle()
{
return CloseWindowStation(handle);
}
}
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool CloseWindowStation(nint hWinsta);
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern SafeWindowStationHandle OpenWindowStation([MarshalAs(UnmanagedType.LPTStr)] string lpszWinSta, [MarshalAs(UnmanagedType.Bool)] bool fInherit, ACCESS_MASK dwDesiredAccess);
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern nint OpenWindowStationW([MarshalAs(UnmanagedType.LPTStr)] string lpszWinSta, [MarshalAs(UnmanagedType.Bool)] bool fInherit, ACCESS_MASK dwDesiredAccess);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetProcessWindowStation(nint hWinSta);
[DllImport("user32.dll")]
public static extern nint GetWindowDC(nint hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(nint hwndParent, EnumWindowsProc lpEnumFunc, nint lParam);
[DllImport("User32.dll")]
public static extern int ReleaseDC(nint hWnd, nint hDC);
[DllImport("User32.dll")]
public static extern nint GetProcessWindowStation();
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetThreadDesktop(nint hDesktop);
[DllImport("user32.dll")]
public static extern nint OpenDesktop(string lpszDesktop, uint dwFlags, bool fInherit, ACCESS_MASK dwDesiredAccess);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool CloseDesktop(nint hDesktop);
public delegate bool EnumDesktopWindowsDelegate(nint hWnd, int lParam);
[DllImport("user32.dll")]
public static extern bool EnumDesktopWindows(nint hDesktop, EnumDesktopWindowsDelegate lpfn, nint lParam);
[DllImport("user32.dll")]
public static extern nint GetDC(nint hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern nint SetActiveWindow(nint hWnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(nint hWnd);
[DllImport("user32.dll")]
public static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize);
[DllImport("user32.dll")]
public static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] InputEx[] pInputs, int cbSize);
[DllImport("user32.dll", SetLastError = false)]
public static extern nuint GetMessageExtraInfo();
[DllImport("sas.dll")]
public static extern void SendSAS(bool asUser);
[DllImport("user32.dll")]
public static extern bool OpenClipboard(nint hWnd);
[DllImport("user32.dll")]
public static extern bool EmptyClipboard();
[DllImport("user32.dll")]
public static extern bool CloseClipboard();
[DllImport("user32.dll")]
public static extern nint SetClipboardData(int Format, nint hMem);
[DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
public static extern bool ShowWindow(nint hWnd, int nCmdShow);
/*
* SystemParametersInfo(
* SPI_SETDESKWALLPAPER, 0, "filename.bmp",
* SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
*/
public const int SPI_SETSCREENSAVEACTIVE = 17;
public const int SPI_SETLOCKSCREENSAVER = 175;
public const int SPI_GETSCREENSAVEACTIVE = 16;
public const int SPI_GETLOCKSCREENSAVER = 174;
public const int SPI_SETFLIGHTMODE = 0x0124;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SystemParametersInfo(
int uAction, int uParam, string lpvParam, int fuWinIni);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(int uAction, int uParam, IntPtr lpvParam, int fuWinIni);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int fuWinIni);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool LockWorkStation();
[DllImport("user32.dll")]
public static extern short VkKeyScan(char ch);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern short VkKeyScanEx(char ch, nint dwhkl);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "BlockInput")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool BlockInput([MarshalAs(UnmanagedType.Bool)] bool fBlockIt);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int MessageBox(nint hWnd, string text, string caption, long type);
[DllImport("USER32.dll")]
public static extern short GetKeyState(VirtualKey nVirtKey);
[DllImport("user32.dll")]
public static extern uint MapVirtualKeyEx(uint uCode, VkMapType uMapType, nint dwhkl);
[DllImport("user32.dll")]
public static extern nint GetKeyboardLayout(uint threadId = 0);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool GetUserObjectInformationW(nint hObj, int nIndex,
[Out] byte[] pvInfo, uint nLength, out uint lpnLengthNeeded);
#endregion
}