I’ve tried
keybd_event(keyByte, 0, KEYEVENTF_KEYDOWN, 0);
Thread.Sleep(3000);
keybd_event(keyByte, 0, KEYEVENTF_KEYUP, 0);
But it only presses it once and pauses, I want it to simulate holding a button. Example if I’m simulating player two in a car game I’ve made and it wants to turn the car while moving forward. The curve is 90 so i then want to hold it for 3 seconds. How to i do this?
EDIT: tried
DateTime start = DateTime.Now;
TimeSpan timespan = DateTime.Now.Subtract(DateTime.Now);
if (timespan.TotalMilliseconds < duration)
{
timespan = DateTime.Now.Subtract(start);
keybd_event(keyByte, 0, KEYEVENTF_KEYDOWN, 0);
}
keybd_event(keyByte, 0, KEYEVENTF_KEYUP, 0);
but without result
You should set a timer for 3 seconds and when it fires, you should release the button.