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.
0:00 InputSender
0:13 Type characters
1:48 Navigation keys
2:35 Extended keys
InputSender Download:
https://www.codeproject.com/Articles/...
C# Automation Playlist:
• C# Automation
Update 2/20/23: Delete and arrow keys called as extended keys to work with any num lock state
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)
}
});
}