I want to send a specific key (e.g. k) to another program named notepad, and below is the code that I used:
private void SendKey()
{
[DllImport ("User32.dll")]
static extern int SetForegroundWindow(IntPtr point);
var p = Process.GetProcessesByName("notepad")[0];
var pointer = p.Handle;
SetForegroundWindow(pointer);
SendKeys.Send("k");
}
But the code doesn't work, what's wrong with the code?
Is it possible that I send the "K" to the notepad without notepad to be the active window? (e.g. active window = "Google chrome", notepad is in the background, which means sending a key to a background application)?