Home > database >  hold down key for x seconds
hold down key for x seconds

Time:09-02

hey i using inputSimulator and want to know how to simulate a Hold keydown for 10 seconds.if you know other instead of inputSimulator, then iam also fine with that. i cannot find any way in C# to do this. i tried it with a timer between or a stopwatch. but this seems not to work. it just press the Key, but not Holding it. also Thread.Sleep is not a good idea as the UI freezes. I need that async.

i cannot understand why this is not easy possible, because it seems to be a simple function.

Hope anyone have a other idea, that i can try :)

sim.Keyboard
// Simulate each key stroke
.KeyDown(VirtualKeyCode.VK_R)

/// Hold key down for 10 seconds!
/// and Release after that time.

.KeyUp(VirtualKeyCode.VK_R);

CodePudding user response:

My Problem is solved by this Code

WORKING CODE

var sim = new InputSimulator();
for (int i = 0; i < 500; i  )
{
    sim.Keyboard.KeyDown(VirtualKeyCode.VK_R);
    Thread.Sleep(10);
}

sim.Keyboard.KeyUp(VirtualKeyCode.VK_R);
  • Related