I would like to simulate a key that is being pressed for few seconds and then it was released. You all know the effect of holding key for a moment ;)
I tried something like this:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
...
const uint WM_KEYDOWN = 0x0100;
const uint WM_KEYUP = 0x0101;
intKeyCode = 'a';
...
PostMessage(windowPointer, WM_KEYDOWN, (IntPtr)(intKeyCode - 0x020), IntPtr.Zero);
Thread.Sleep(5000); // Sleep for 5 sec
PostMessage(windowPointer, WM_KEYUP, (IntPtr)(intKeyCode - 0x020), IntPtr.Zero);
Result is easy to predict. It shows only two letters instead of typing it few times for first 5 seconds.
Does anyone tried something like this?