C# - Simulate keystrokes with SendInput (codeproject implementation) @JFLHV
C# - Simulate keystrokes with SendInput (codeproject implementation)  @JFLHV
Uploaded October 2022 | Updated September 2026, 1 week ago
Simulate keyboard keystrokes in Windows apps using C# SendInput function. A download from codeproject.com is used to build functions that type text, press navigation keys and extended keys.

Update 02/20/23: Delete and arrow keys called as extended keys to work with any num lock state

Update 12/2/25: In the method to type a string, I had to add a Thread.Sleep after each character to prevent faster systems from dropping characters. I suggest making that delay configurable with default of 5-10ms.

0:00 InputSender
0:13 Type characters
1:48 Navigation keys
2:35 Extended keys

InputSender Download:
codeproject.com/Articles/5264831/How-to-Send-Inputs-using-Csharp

C# Automation Playlist:
youtube.com/playlist?list=PLAW4P1Sb_oJbIJIQd8-HPmsVUE6Ez6NFL&si=3rb4bQHNPmHYsaXs

#csharp

Code:
private static void PressCombo(ushort code1, ushort code2)
{

InputSender.SendKeyboardInput(new InputSender.KeyboardInput[]
{
new InputSender.KeyboardInput
{
wScan = code1,
dwFlags = (uint)(InputSender.KeyEventF.KeyDown | InputSender.KeyEventF.Scancode)
},
new InputSender.KeyboardInput
{
wScan = code2,
dwFlags = (uint)(InputSender.KeyEventF.KeyDown | InputSender.KeyEventF.Scancode)
}
});


InputSender.SendKeyboardInput(new InputSender.KeyboardInput[]
{
new InputSender.KeyboardInput
{
wScan = code2,
dwFlags = (uint)(InputSender.KeyEventF.KeyUp | InputSender.KeyEventF.Scancode)
},
new InputSender.KeyboardInput
{
wScan = code1,
dwFlags = (uint)(InputSender.KeyEventF.KeyUp | InputSender.KeyEventF.Scancode)
}
});


}




private static void PressExtended(ushort code)
{

InputSender.SendKeyboardInput(new InputSender.KeyboardInput[]
{
new InputSender.KeyboardInput
{
wScan = 0xe0,
dwFlags = (uint)(InputSender.KeyEventF.ExtendedKey | InputSender.KeyEventF.Scancode),
},
new InputSender.KeyboardInput
{
wScan = code,
dwFlags = (uint)(InputSender.KeyEventF.ExtendedKey | InputSender.KeyEventF.Scancode)
}
});
}
C# - Simulate keystrokes with SendInput (codeproject implementation)Fading circle green screen overlayC# - Creating a hobby automation appCast locked files from Google Pixel Private SpaceHeart animation green screenHow align works in Microsoft Publisher | Windows 10Checkmark green screenNow Playing feature Google Pixel 7Print test page in Windows 10VB.NET - Creating multiple controls at runtime inside flow layout panelChange YouTube Shorts thumbnail after uploadTodays date keyboard shortcut Excel
JFLHV |

C# - Simulate keystrokes with SendInput (codeproject implementation)

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER