c# - Disable or redirect keyboard input made to spawned subprocesses -


I have a calculator that comes with Windows. I wrote a C # application to launch it.

  Public Partial Sections Form 1: Form {Public Form 1 () {InitializeComponent (); } Private Zero Button 1_Click (Object Sender, EventArgs e) {Process Proc = New Process (); Proc.StartInfo.FileName = "Calc"; Proc.Start (); }}  

I am interested in whether I can suppress main input in subprances. For example, in the calculator you can kill the number keys to enter the input.

Is it possible to do my keys through my application? Or, is it possible to force all input to go through the calculator first through your application?

For example, suppose I want to make it so that the calculator is nothing by pressing number 5, the calculator was launched using my application.

Yes, you can redirect to the standard input stream, which allows the user to log in directly to the console window To Your program can write process to send input to Process.StandardInput (which is TextWriter ).

Change it to your click handler:

  Private Zero Button 1_Click (Object Sender, EventArgs e) {Process Proc = New Process (); Proc.StartInfo.FileName = "Calc"; Proc.StartInfo.UseShellExecute = false; Proc.StartInfo.RedirectStandardInput = True; Proc.EnableRaisingEvents = True; _proc.exact + = (Sender1, E1) = & gt; Process.Dispose (); Proc.Start (); }  

Three notes:

  • You need to explicitly maintain the context of the process example, or at least Less its standard input object, if you want to actually type it on its input stream
  • You have to reset the wrong to use UseShellExecute to work, whatever the behavior of some automated process class (for example executable) Instead of specifying a file) it may or may not be in your specific scenario.
  • After the process is finished, it is best to settle the process object. I have been able to handle some code in the above example (to enable the increase of events, and then by handling the process object exited event handling Does

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -