Simulate a keypress for X seconds
c#, winforms
Solution
The repeating of a keystroke when you hold it down is a feature that's built into the keyboard controller. A microprocessor that's built into the keyboard itself. The 8042 microcontroller was the traditional choice, the keyboard device driver still carries its name.
So, no, this is not done by Windows and PostMessage() is not going to do it for you. Not exactly a problem, you can simply emulate it with a Timer.
Problem
Here is my code that I use to simulate a tab-keypress in a certain process: ``` [DllImport("user32.dll")] static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam); public Form1() { PostMessage(MemoryHandler.GetMainWindowHandle(), (int)KeyCodes.WMessages.WM_KEYDOWN, (int)KeyCodes.VKeys.VK_TAB, 0); InitializeComponent(); } ``` Is there any way to extend it so that it presses the key for (example) 1 second, instead of just tapping it? Please note that I'm not interested in a `Thread.Sleep()` solution that blocks the UI thread.