Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7694925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:25:45+00:00 2026-05-31T21:25:45+00:00

I have an issue regarding Sendkeys Class, as i want to use this class

  • 0

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

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

End Class

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?

LATER EDIT : In meantime i have found another example

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

If in background i have two applications :

  1. Visual Studio
  2. Target application

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)?

Later Edit2
strong text
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

Module Module1

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

End Module

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:25:46+00:00Added an answer on May 31, 2026 at 9:25 pm

    In order to sendkey to another application, you need to first activate that application on the button click and then send keys

    MSDN Link

    // Get a handle to an application window.
    [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(string lpClassName,
        string lpWindowName);
    
    // Activate an application window.
    [DllImport("USER32.DLL")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);
    
    // Send a series of key presses to the Calculator application.
    private void button1_Click(object sender, EventArgs e)
    {
        // Get a handle to the Calculator application. The window class
        // and window name were obtained using the Spy++ tool.
        IntPtr calculatorHandle = FindWindow("CalcFrame","Calculator");
    
        // Verify that Calculator is a running process.
        if (calculatorHandle == IntPtr.Zero)
        {
            MessageBox.Show("Calculator is not running.");
            return;
        }
    
        // Make Calculator the foreground application and send it 
        // a set of calculations.
        SetForegroundWindow(calculatorHandle);
        SendKeys.SendWait("111");
        SendKeys.SendWait("*");
        SendKeys.SendWait("11");
        SendKeys.SendWait("=");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have some issue regarding constructor and destructor. I have list class, which
I have seen a few posts regarding this issue but not one specific to
I have an other active question HERE regarding some hopeless memory issues that possibly
I have a prickly design issue regarding the choice of database technologies to use
I have an issue regarding the use of the following regular expression: private Regex
I have some issue regarding display name of property in result of get request
I have an issue regarding style my blog. I want to make the header
I have already found a previous SF question regarding this issue and I believe
I find git docs very cryptic regarding this issue. I want to do a
I have read many posts on here regarding this issue; The answers of 'Why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.