How can I send the F4 key to a process in C#? -
I'm starting a process from a Windows application. When I press a button, I want to simulate pressing the key F4 in that process. How can I do this?
[edit later] I do not want to suppress the F4 key in my form, but in this process I started.
To send an F4 key to another process, you must activate that process
Recommend:
- Get process class impressions initiated by the process. Start
- Query Process Manvindohndale
- Unmanaged Win32 API Function "ShowOindo" or "SwitchToWindow"
Then you use System.Windows.Forms.SendKeys.Send ("{F4}")
Edit:
The example code below runs Notepad and for this "ABC" Sends:
using the system; Using System.Diagnostics; Using System.Runtime.InteropServices; Using System.Windows.Forms; Namespace textSend {class program {[DllImport ("user32.dll")] Fixed external ball show (intimate hwnd, int ncmd show); Static zero main (string [] args) {process notepad = new process (); Notepad.StartInfo.FileName = @ "C: \ Windows \ notepad.exe"; Notepad.start (); // Notepad should wait for Notepad to start. WaitForInputIdle (); IntPtr p = notepad.MainWindowHandle; ShowWindow (P, 1); SendKeys.SendWait ("ABC"); }}}
Comments
Post a Comment