-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWin32Interop.cs
More file actions
226 lines (214 loc) · 8.1 KB
/
Win32Interop.cs
File metadata and controls
226 lines (214 loc) · 8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
using System;
using System.Runtime.InteropServices;
namespace MultipleMice.Native
{
internal sealed class Win32Interop
{
// Fields
internal const byte AC_SRC_ALPHA = 1;
internal const byte AC_SRC_OVER = 0;
internal const int APPCOMMAND_BROWSER_BACKWARD = 1;
internal const int APPCOMMAND_BROWSER_FORWARD = 2;
internal const int FAPPCOMMAND_MOUSE = 32768;
internal const int GWL_EXSTYLE = -20;
internal const uint INPUT_HARDWARE = 2;
internal const uint INPUT_KEYBOARD = 1;
internal const uint INPUT_MOUSE = 0;
internal const int KeyboardDelayMax = 3;
internal const int KeyboardDelayMin = 0;
internal const int KeyboardSpeedMax = 31;
internal const int KeyboardSpeedMin = 0;
internal const int KEYEVENTF_EXTENDEDKEY = 1;
internal const int KEYEVENTF_KEYUP = 2;
internal const int KEYEVENTF_SCANCODE = 8;
internal const int KEYEVENTF_UNICODE = 4;
internal const int MA_ACTIVATE = 1;
internal const int MA_ACTIVATEANDEAT = 2;
internal const int MA_NOACTIVATE = 3;
internal const int MA_NOACTIVATEANDEAT = 4;
internal const ushort MK_LBUTTON = 1;
internal const ushort MK_RBUTTON = 2;
internal const uint MOUSEEVENTF_ABSOLUTE = 32768;
internal const uint MOUSEEVENTF_RIGHTDOWN = 8;
internal const uint MOUSEEVENTF_RIGHTUP = 16;
internal const uint MOUSEEVENTF_VIRTUALDESK = 16384;
internal const uint MOUSEEVENTF_WHEEL = 2048;
internal const int SB_LINEDOWN = 1;
internal const int SB_LINEUP = 0;
internal const int SB_PAGEDOWN = 3;
internal const int SB_PAGEUP = 2;
internal const int SM_CXVIRTUALSCREEN = 78;
internal const int SM_CYVIRTUALSCREEN = 79;
internal const int SM_XVIRTUALSCREEN = 76;
internal const int SM_YVIRTUALSCREEN = 77;
internal const uint SMTO_ABORTIFHUNG = 2;
internal const uint SMTO_BLOCK = 1;
internal const uint SMTO_NORMAL = 0;
internal const uint SMTO_NOTIMEOUTIFNOTHUNG = 8;
internal const uint SPI_GETKEYBOARDDELAY = 22;
internal const uint SPI_GETKEYBOARDSPEED = 10;
internal const uint SPI_GETWHEELSCROLLLINES = 104;
internal const uint SPI_SETWHEELSCROLLLINES = 105;
internal const uint SPIF_SENDWININICHANGE = 2;
internal const uint SPIF_UPDATEINIFILE = 1;
internal const int ULW_ALPHA = 2;
internal const int ULW_COLORKEY = 1;
internal const int ULW_OPAQUE = 4;
internal const ushort VK_CONTROL = 17;
internal const ushort VK_DELETE = 46;
internal const ushort VK_END = 35;
internal const ushort VK_ESCAPE = 27;
internal const ushort VK_F4 = 115;
internal const ushort VK_HOME = 36;
internal const ushort VK_LWIN = 91;
internal const ushort VK_MENU = 18;
internal const ushort VK_RETURN = 13;
internal const ushort VK_RWIN = 92;
internal const ushort VK_SHIFT = 16;
internal const ushort VK_TAB = 9;
internal const uint WHEEL_DELTA = 120;
internal const uint WHEEL_PAGESCROLL = uint.MaxValue;
internal const int WM_APPCOMMAND = 793;
internal const int WM_HSCROLL = 276;
internal const int WM_MOUSEACTIVATE = 33;
internal const int WM_MOUSEWHEEL = 522;
internal const int WM_RBUTTONDOWN = 516;
internal const int WM_RBUTTONUP = 517;
internal const int WM_VSCROLL = 277;
internal const int WS_EX_LAYERED = 524288;
internal const int WS_EX_NOACTIVATE = 134217728;
internal const int WS_EX_TOOLWINDOW = 128;
internal const int WS_EX_TRANSPARENT = 32;
// Methods
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern BOOL DeleteDC(IntPtr hdc);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern BOOL DeleteObject(IntPtr hObject);
[DllImport("user32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern IntPtr FindWindowA([MarshalAs(UnmanagedType.LPStr)] string lpClassName, [MarshalAs(UnmanagedType.LPStr)] string lpWindowName);
[DllImport("user32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll", ExactSpelling = true)]
public static extern int GetSystemMetrics(int nIndex);
[DllImport("user32.dll", SetLastError = true)]
internal static extern int GetWindowThreadProcessId(IntPtr hWnd, out IntPtr lpdwProcessId);
[DllImport("user32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern BOOL PostMessageW(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern uint RegisterWindowMessageW([MarshalAs(UnmanagedType.LPWStr)] string lpString);
[DllImport("user32.dll", ExactSpelling = true)]
internal static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("user32.dll", SetLastError = true)]
public static extern BOOL ScreenToClient(IntPtr hWnd, ref POINT lpPoint);
[DllImport("gdi32.dll", ExactSpelling = true)]
internal static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
[DllImport("user32.dll", SetLastError = true)]
internal static extern int SendInput(int nInputs, INPUT[] pInputs, int cbSize);
[DllImport("user32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern BOOL SendMessageTimeoutW(IntPtr hWnd, uint msg, int wParam, int lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);
[DllImport("user32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern BOOL SendMessageW(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern BOOL SystemParametersInfoW(uint uiAction, uint uiParam, out IntPtr pvParam, uint fWinIni);
[DllImport("user32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern BOOL UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
[DllImport("user32.dll", ExactSpelling = true)]
internal static extern IntPtr WindowFromPoint(POINT Point);
// Nested Types
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private struct ARGB
{
public byte Blue;
public byte Green;
public byte Red;
public byte Alpha;
public ARGB(byte Alpha, byte Red, byte Green, byte Blue)
{
this.Alpha = Alpha;
this.Red = Red;
this.Green = Green;
this.Blue = Blue;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct BLENDFUNCTION
{
public byte BlendOp;
public byte BlendFlags;
public byte SourceConstantAlpha;
public byte AlphaFormat;
}
public enum BOOL
{
FALSE,
TRUE
}
[StructLayout(LayoutKind.Sequential)]
internal struct HARDWAREINPUT
{
internal uint uMsg;
internal ushort wParamL;
internal ushort wParamH;
}
[StructLayout(LayoutKind.Sequential)]
internal struct INPUT
{
internal uint type;
internal Win32Interop.INPUTUNION data;
}
[StructLayout(LayoutKind.Explicit)]
internal struct INPUTUNION
{
// Fields
[FieldOffset(0)]
internal Win32Interop.HARDWAREINPUT hi;
[FieldOffset(0)]
internal Win32Interop.KBDINPUT ki;
[FieldOffset(0)]
internal Win32Interop.MOUSEINPUT mi;
}
[StructLayout(LayoutKind.Sequential)]
internal struct KBDINPUT
{
internal ushort vKey;
internal ushort scanCode;
internal uint flags;
internal uint time;
internal UIntPtr extraInfo;
}
[StructLayout(LayoutKind.Sequential)]
internal struct MOUSEINPUT
{
internal int dx;
internal int dy;
internal uint mouseData;
internal uint dwFlags;
internal uint time;
internal UIntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SIZE
{
public int cx;
public int cy;
public SIZE(int cx, int cy)
{
this.cx = cx;
this.cy = cy;
}
}
}
}