[Gtk-sharp-list] Send keystroke to gtk window with proccess.start(xsendkeycode)

toogooda andrew at toogoods.co.nz
Wed Mar 3 01:15:40 EST 2010


I am no expert but you can't do it from two process as you want the key
stokes to go to the first process.

have a read of this tutoral on the win platform,

Controlling process input/output.

You may need to send input directly to a launched process and send the
output directly back to your program. For programs that use StdIn, StdOut,
and StdErr, such as console applications, you can override the defaults and
provide a StreamWriter to write input and StreamReaders to read the StdOut
and StdErr outputs.

.NET uses the Win32 ShellExecute function to launch processes so when you
want to reassign I/O streams, you must set the
ProcessStartInfo.UseShellExecute property False before starting the process.
Also, you must either specify the full path to the file, or the file
location must be in the environment path string or in one of the places
Windows searches for files.

    Dim myProcess As Process = New Process()
    Dim s As String myProcess.StartInfo.FileName = "cmd.exe"
    
    myProcess.StartInfo.UseShellExecute = False
    myProcess.StartInfo.CreateNoWindow = True 
    myProcess.StartInfo.RedirectStandardInput = True 
    myProcess.StartInfo.RedirectStandardOutput = True
    myProcess.StartInfo.RedirectStandardError = True
    myProcess.Start() 

    Dim sIn As StreamWriter = myProcess.StandardInput 
    Dim sOut As StreamReader = myProcess.StandardOutput 
    Dim sErr As StreamReader = myProcess.StandardError
 
    sIn.AutoFlush = True 
    sIn.Write("dir c:\windows\system32\*.com" & System.Environment.NewLine) 
    sIn.Write("exit" & System.Environment.NewLine) 
    s = sOut.ReadToEnd()
 
    If Not myProcess.HasExited Then 
        myProcess.Kill() 
    End If 

    MessageBox.Show("The 'dir' command window was " & _
        closed at: " & myProcess.ExitTime & "." & _ 
        System.Environment.NewLine & "Exit Code: " & myProcess.ExitCode) 

    sIn.Close() 
    sOut.Close() 
    sErr.Close() 
    myProcess.Close() 
    MessageBox.Show(s) 
For programs that don't use StdIn, you can use the SendKeys method to input
keystrokes.

    Dim myProcess As Process = New Process()

    myProcess.StartInfo.FileName = "notepad"
    myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
    myProcess.EnableRaisingEvents = True

    AddHandler myProcess.Exited, AddressOf Me.SendKeysTestExited
    myProcess.Start()
    '   
    ' Wait until the program is ready for input.
    '
    myProcess.WaitForInputIdle(1000)

    If myProcess.Responding Then
        System.Windows.Forms.SendKeys.SendWait( _
                "This text was entered using SendKeys.")
    Else
        myProcess.Kill()
    End If
-- 
View this message in context: http://n4.nabble.com/Send-keystroke-to-gtk-window-with-proccess-start-xsendkeycode-tp1546856p1576118.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.


More information about the Gtk-sharp-list mailing list