Library to send mouse and key Inputs

I have a project where i need to send Mouse and Key Inputs on a Global level from my WindowsForms application. I need somethig like https://www.nuget.org/packages/H.InputSimulator#readme-tab, the only problem ive got with this library is that once i send the key i cant get it to be held down, a crucial point of the project is that i need to simulate the held down key for a small amount of time (for example if i hold the key down for 2 seconds i get: lllllllllllllllllllllllllllllll). Does anyone know a library that is able to do that or know a way to do that with the given library?
H.InputSimulator 1.4.1
Allows you to simulate global mouse and keyboard events. Features: - Supports scan codes and multi-language input. - Supports WPF/WinForms/Console windows apps. - Supports .NET Standard, .Net Core and .Net 5/6. Supported OS: - Windows
6 Replies
Buddy
Buddy5mo ago
What are you trying to make?
RohesKätzchen
RohesKätzchen5mo ago
A programm that can record mouse and keybord strokes and replay them, i call it a macro recorder, i have the recording part done now i need to do the play part
MeGaLoDoN
MeGaLoDoN5mo ago
GitHub
GitHub - michaelnoonan/inputsimulator: Windows Input Simulator (C# ...
Windows Input Simulator (C# SendInput Wrapper - Simulate Keyboard and Mouse) - GitHub - michaelnoonan/inputsimulator: Windows Input Simulator (C# SendInput Wrapper - Simulate Keyboard and Mouse)
RohesKätzchen
RohesKätzchen5mo ago
thanks this might be just what i need. i cant get the key to be held down, do you know what i have done wrong?
InputSimulator inputSimulator = new InputSimulator();

private void button1_Click(object sender, EventArgs e)
{
this.ActiveControl = textBox1;

inputSimulator.Keyboard.Sleep(2000)
.KeyDown(VirtualKeyCode.VK_D)
.Sleep(2000)
.KeyUp(VirtualKeyCode.VK_D);

MessageBox.Show("Done");
}
InputSimulator inputSimulator = new InputSimulator();

private void button1_Click(object sender, EventArgs e)
{
this.ActiveControl = textBox1;

inputSimulator.Keyboard.Sleep(2000)
.KeyDown(VirtualKeyCode.VK_D)
.Sleep(2000)
.KeyUp(VirtualKeyCode.VK_D);

MessageBox.Show("Done");
}
hey i still couldnt figure out how to hold the key down, do you have an idea?
MeGaLoDoN
MeGaLoDoN5mo ago
Try to use async method and call KeyDown then await Task.Delay(2000) and then KeyUp
RohesKätzchen
RohesKätzchen4mo ago
private async void HoldDown()
{
this.ActiveControl = textBox1;

inputSimulator.Keyboard.Sleep(2000).KeyDown(VirtualKeyCode.VK_D);
await Task.Delay(2000);
inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_D);
}
private async void HoldDown()
{
this.ActiveControl = textBox1;

inputSimulator.Keyboard.Sleep(2000).KeyDown(VirtualKeyCode.VK_D);
await Task.Delay(2000);
inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_D);
}
i tried doing it like this but this also doesnt work i just noticed that whenn i try it in a game for example minecraft the key actually gets held down so i can walk, but when i try it in a text Programm it only gets a single input