Repository navigation
Expand file tree
/
Copy pathNativeInput.cs
More file actions
63 lines (55 loc) · 1.67 KB
/
Copy pathNativeInput.cs
File metadata and controls
63 lines (55 loc) · 1.67 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
using System.Runtime.InteropServices;
namespace MidiShortcuts;
/// <summary>
/// Envoltorio de la API SendInput de user32.dll para simular teclas y
/// texto, sin depender de ninguna libreria externa (equivalente al uso
/// que hacia el proyecto en Python de la libreria "keyboard").
/// </summary>
internal static class NativeInput
{
internal const uint INPUT_KEYBOARD = 1;
internal const uint KEYEVENTF_EXTENDEDKEY = 0x0001;
internal const uint KEYEVENTF_KEYUP = 0x0002;
internal const uint KEYEVENTF_UNICODE = 0x0004;
[StructLayout(LayoutKind.Sequential)]
internal struct KEYBDINPUT
{
public ushort wVk;
public ushort wScan;
public uint dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
internal struct MOUSEINPUT
{
public int dx;
public int dy;
public uint mouseData;
public uint dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
internal struct HARDWAREINPUT
{
public uint uMsg;
public ushort wParamL;
public ushort wParamH;
}
[StructLayout(LayoutKind.Explicit)]
internal struct InputUnion
{
[FieldOffset(0)] public MOUSEINPUT mi;
[FieldOffset(0)] public KEYBDINPUT ki;
[FieldOffset(0)] public HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Sequential)]
internal struct INPUT
{
public uint type;
public InputUnion U;
}
[DllImport("user32.dll", SetLastError = true)]
internal static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
}