Click here to Skip to main content
15,035,600 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi all,
I am trying to send some key strokes to another running application after activating it. I used notepad for example. But sometimes it works and most of times not. Following is the code I am using. Please anybody findout what is wrong in the code. If it can not be corrected please redirect me to some other nice ways to send keystrokes to other applications.

Thanks in advance

Here is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace send
    public partial class Form1 : Form

        private static extern int FindWindow(String ClassName, String WindowName);

        private static extern IntPtr SetForegroundWindow(int hWnd);

        static extern bool SetForegroundWindow(IntPtr hWnd);

        public Form1()

        private void button2_Click(object sender, EventArgs e)

            int hWnd = FindWindow(null, "New Text Document.txt - Notepad");
            if (hWnd > 0)

                MessageBox.Show("Window Not Found!");




i use smeller way to interactive with SKYPe but as you know sometimes it works and others not so i try to find a library to interactive SKYpe and it works fine,
if the idea not works with you, you can try what i tried before you can make the process high priority.
hop it helps
Thank u for ur immediate reply. Can u make it some more clear? I mean with some code snippets? Really I don't know what u mean by library.
I tried to use Postmessage. It works fine with string values just like 'abc'. But i don't know how to post {TAB} or {ENTER} using it. Anybody please help.
:laugh: Yes, I found it. I used postmessage function. It works fine.

It works fine with main application window, but I have to send keystrokes to childwindow of that application(specifically dialog window). I couldn't get handle of the child window. If anybody can please help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900