You can send key stokes virtually to other applications with this:

This code will send F11 key press to Mozilla Firefox, which will make it ‘fullscreen’.

int iHandle = FindWindow(null, "Mozilla Firefox");
SetForegroundWindow(iHandle);
SendKeys.Send("{F11}");

FindWindow and SetForegroundWindow are APIs, which you can access with


[DllImport("user32.dll")]
public static extern int FindWindow(
string lpClassName, // class name
string lpWindowName // window name
);
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(
int hWnd // handle to window
);

Full cs 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 WindowsApplication1
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern int FindWindow(
string lpClassName, // class name
string lpWindowName // window name
);
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(
int hWnd // handle to window
);
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int iHandle = FindWindow(null, “Mozilla Firefox”);SetForegroundWindow(iHandle);SendKeys.Send(”A”);

}
}
}

VN:F [1.1.6_502]
Rating: 0.0/5 (0 votes cast)
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • DotNetKicks
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati

Related posts:

  1. Visual SourceSafe Programming
  2. Simple WPF ViewModel implementaion with VisualBasic.NET
  3. MD5 encryption with c#
  4. Move a control with mouse on form
  5. Get currently logged in user from a service running under LocalSystem account