111,129
社区成员
发帖
与我相关
我的任务
分享
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT
{
public int dx;
public int dy;
public int mouseData;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
struct KEYBDINPUT
{
public ushort wVk;
public ushort wScan;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
struct HARDWAREINPUT
{
public int uMsg;
public ushort wParamL;
public ushort wParamH;
}
[StructLayout(LayoutKind.Explicit)]
struct INPUT
{
[FieldOffset(0)]
public int type;
[FieldOffset(4)]
public MOUSEINPUT mi;
[FieldOffset(4)]
public KEYBDINPUT ki;
[FieldOffset(4)]
public HARDWAREINPUT hi;
}
[DllImport("user32.dll")]
static extern uint SendInput(uint nInputs, INPUT pInputs, int cbSize);
public static void Send(string message)
{
for (int i = 0; i < message.Length; i++)
{
INPUT input = new INPUT();
input.type = 1;
input.ki.wVk = (ushort)message[i];
input.ki.dwFlags = 1;
SendInput(1, input, Marshal.SizeOf(input));//keydown
INPUT input1 = new INPUT();
input1.type = 1;
input1.ki.wVk = (ushort)message[i];
input1.ki.dwFlags = 0x0002;
SendInput(1, input1, Marshal.SizeOf(input1));//keyup
}
}