The SendInput function synthesizes keystrokes, mouse motions, and button clicks to the currently active window
/// <summary>
/// Synthesizes keystrokes, mouse motions, and button clicks.
/// </summary>
[DllImport("user32.dll")]
internal static extern UINT SendInput(
UINT nInputs,
[MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs,
int cbSize);
Private Declare Function SendInput Lib "user32.dll" (ByVal cInputs As Integer, ByRef pInputs As INPUT, ByVal cbSize As Integer) As Integer
look over here.
http://www.pinvoke.net/default.aspx/Structures/INPUT.html
Please add some!
var pInputs = new[]
{
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S,
dwFlags = EnumLib.KEYEVENTF.KEYUP
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S,
dwFlags = EnumLib.KEYEVENTF.KEYUP
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S
}
},
new StructLib.INPUT()
{
type = EnumLib.INPUT_TYPE.INPUT_KEYBOARD,
ki = new StructLib.KEYBDINPUT()
{
wScan = EnumLib.ScanCodeShort.KEY_S,
wVk = EnumLib.VirtualKeyShort.KEY_S,
dwFlags = EnumLib.KEYEVENTF.KEYUP
}
}
};
var hWindow = Api.user32.FindWindow("notepad", null);
Api.user32.SetForegroundWindow(hWindow);
Thread.Sleep(2500);
Api.user32.SendInput(
(uint)pInputs.Length, pInputs, StructLib.INPUT.Size);