Hi i am working on windows application . I am opening an math type using button want to select all and copy send keys are not working
here is my code ...

Dim proc As New Process()

        With proc.StartInfo
            .Arguments = "file_path.bmp"
            .UseShellExecute = True
            .WindowStyle = ProcessWindowStyle.Normal
            .WorkingDirectory = "C:\Windows\System32\" 'path name
            .FileName = "mathtype.exe" '<----- Set  Exe Name
        End With
        proc.Start()
              proc.Close()
        proc.Dispose()

        System.Windows.Forms.SendKeys.Send("^A") 'use keys
        System.Windows.Forms.SendKeys.Send("^C")

help me!

Edited 5 Years Ago by __avd: Added [code] tags.

Also, give your system time to process what you've asked it to do before sending the keystrokes by inserting the following prior to the send keys:

System.Threading.Thread.Sleep(500)

use proc.WaitForInputIdle() it will kind of halt your application until the main window of the proc is created ..
here is a code suggestion

Dim proc As New Process()

        With proc.StartInfo
            .Arguments = "c:\equ.wmf"
            .UseShellExecute = True
            .WindowStyle = ProcessWindowStyle.Normal
            .WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\MathType"
            .FileName = "mathtype.exe" '<----- Set Exe Name
            If Not My.Computer.FileSystem.FileExists(.WorkingDirectory & "\" & .FileName) Then
                Exit Sub
            End If
        End With

        proc.Start()
        proc.WaitForInputIdle()
        Threading.Thread.Sleep(500)
        System.Windows.Forms.SendKeys.Send("^q") 'use keys
        System.Windows.Forms.SendKeys.Send("^c")
        proc.CloseMainWindow()
        proc.Dispose()

what i have changed is:
- the path to "mathtype.exe" (it is in my machine's program files)
- the "select all" sequence (q) and the "copy" sequence ('c' lower case)
=> check the edit menu to make sure about them.

PS: if you want to let's say paste the equation inside a richtextbox then you must
make some delay i.e.

Threading.Thread.Sleep(1)
        RichTextBox1.Paste()

screen capture

Edited 6 Years Ago by ÜnLoCo: n/a

Hi, I am used this code but how to use it without timer it cant paste after timing is over it paste only '

Threading.Thread.Sleep(1)
        Richtextbox1.Paste()
in the richtextbox

Dim proc As New Process()

        With proc.StartInfo
            .Arguments = "c:\equ.wmf"
            .UseShellExecute = True
            .WindowStyle = ProcessWindowStyle.Normal
            .WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\MathType"
            .FileName = "mathtype.exe" '<----- Set Exe Name
            If Not My.Computer.FileSystem.FileExists(.WorkingDirectory & "\" & .FileName) Then
                Exit Sub
            End If
        End With

        proc.Start()
        proc.WaitForInputIdle()
        Threading.Thread.Sleep(500)
        System.Windows.Forms.SendKeys.Send("^q") 'use keys
        System.Windows.Forms.SendKeys.Send("^c")
        proc.CloseMainWindow()
        proc.Dispose()

        Threading.Thread.Sleep(1)
        Richtextbox1.Paste()

Edited 5 Years Ago by __avd: Added [code] tags. Do wrap your programming code blocks within [code] ... [/code] tags

Maybe you can try changing a little the order or sentences

proc.Start()
proc.WaitForInputIdle()
Threading.Thread.Sleep(500)

System.Windows.Forms.SendKeys.Send("^q") 'use keys
Threading.Thread.Sleep(1)

System.Windows.Forms.SendKeys.Send("^c")
Threading.Thread.Sleep(1)

Richtextbox1.Paste() 

proc.CloseMainWindow()
proc.Dispose()

Hope this helps

Edited 6 Years Ago by lolafuertes: n/a

Hi i am used this code its working. thanks
but one last question is that without using the thread how i can use it when i close the exe application(math type). it copy and paste into richtextbox.

Here is my code

Dim proc As New Process()

        With proc.StartInfo
            .Arguments = "c:\equ.wmf"
            .UseShellExecute = True
            .WindowStyle = ProcessWindowStyle.Normal
            .WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\MathType"
            .FileName = "mathtype.exe" '<----- Set Exe Name
            If Not My.Computer.FileSystem.FileExists(.WorkingDirectory & "\" & .FileName) Then
                Exit Sub
            End If
        End With

        proc.Start()
        proc.WaitForInputIdle()


        Threading.Thread.Sleep(5000)

        System.Windows.Forms.SendKeys.Send("^a") 'use keys
        System.Windows.Forms.SendKeys.Send("^c")
        rtxtnarration.Focus()
        'SendKeys("^v", True)
        rtxtnarration.Paste()
        ' proc.CloseMainWindow()
        proc.Dispose()

Edited 5 Years Ago by __avd: Added [code] tags. Do wrap your programming code blocks within [code] ... [/code] tags

This article has been dead for over six months. Start a new discussion instead.