I need to simulate a keypress in a third party application. Let\'s say I have a C# application that needs to send an \"8\" to the Calculator application. I can\'t use the Se
The solution here helped me but I had to edit it, also it's now shorter:
Also here a usefull list of Virtual Key Codes
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
private void button1_Click(object sender, EventArgs e)
{
const int WM_SYSKEYDOWN = 0x0104;
IntPtr WindowToFind = FindWindow(null, "Calculator");
PostMessage(WindowToFind, WM_SYSKEYDOWN, ((int)Keys.NumPad7), 0);
}