title: Simple Application for sending Keystroke in VB.NET
body: <p>I have an issue regarding Sendkeys Class, as i want to use this class in order to send some keystroke to the active application.
  As a first step i want to test the {Enter} keystroke, so in order to achieve that i made a simple application in vb.net 2010</p>
  
  <pre><code>Public Class Form1
  Public Shared data As String
  Private Sub SendintText(command As String)
      Try
          SendKeys.SendWait(command)
      Catch e As Exception
          MsgBox(e.StackTrace)
      End Try
  End Sub
  
  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
      data = TextBox1.Text.ToString
      SendingText(data)
  End Sub
  </code></pre>
  
  <p>End Class</p>
  
  <p>When i tried to run for {Enter} i have received infinit loop error:
  An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll
  Could someone help me? </p>
  
  <p>LATER EDIT : In meantime i have found another example </p>
  
  <pre><code>Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      System.Threading.Thread.Sleep(2000)
      SendKeys.SendWait("{ENTER}")
  End Sub
  </code></pre>
  
  <p>If in background i have two applications :</p>
  
  <ol>
  <li>Visual Studio </li>
  <li>Target application</li>
  </ol>
  
  <p>How can i focus on the target application, because now when i am running the form , that form became active..is there any solution to call the winform from command prompt with some parameter (the key that i want to send)?</p>
  
  <p>Later Edit2
  <strong>strong text</strong>
  i have give it up the idea for windows form, so finnally i have made a simple program in console application that simulates the keystroke ...                                           Imports System
  Imports System.Windows.Forms</p>
  
  <p>Module Module1</p>
  
  <pre><code>Sub Main(ByVal args() As String)
      Dim data As String = args(0)
      Console.WriteLine("You insert the : {0}", data)
      System.Threading.Thread.Sleep(5000)
      SendKeys.SendWait(data)
  End Sub
  </code></pre>
  
  <p>End Module</p>
  
  <p>By the way in order to use double quotes in a parameter you need \"test\"...(i have spent 15 min to find out) so it might be usefull...
  Thanks again for the informations.</p>