110,534
社区成员
发帖
与我相关
我的任务
分享
[DllImport("user32.dll")]
public static extern unit SendInput(unit nInput,ref IInput[] pInputs int cbSize);
public interface IInput {}
public struct MouseInput : IInput {}
public struct KeyBoardInput : IInput {}
public struct HardWareInput : IInput {}
[DllImport("user32.dll")]
public static extern UInt32 SendInput(UInt32 nInputs, ref INPUT pInputs, int cbSize);
[StructLayout(LayoutKind.Explicit)]
public struct INPUT
{
[FieldOffset(0)]
public Int32 type;
[FieldOffset(4)]
public KEYBDINPUT ki;
[FieldOffset(4)]
public MOUSEINPUT mi;
[FieldOffset(4)]
public HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Sequential)]
public struct MOUSEINPUT
{
public Int32 dx;
public Int32 dy;
public Int32 mouseData;
public Int32 dwFlags;
public Int32 time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct KEYBDINPUT
{
public Int16 wVk;
public Int16 wScan;
public Int32 dwFlags;
public Int32 time;
public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct HARDWAREINPUT
{
public Int32 uMsg;
public Int16 wParamL;
public Int16 wParamH;
}
public const int INPUT_KEYBOARD = 1;
public const int KEYEVENTF_KEYUP = 0x0002;
private void button1_Click(object sender, EventArgs e)
{
INPUT inDown = new INPUT();
inDown.type = INPUT_KEYBOARD;
inDown.ki.wVk = (int)Keys.A;
inDown.ki.dwFlags = KEYEVENTF_KEYUP;
this.Text = SendInput(1, ref inDown, Marshal.SizeOf(inDown)).ToString();
}