Form Design:
[highlight="C#"]
namespace SendKeys
{
partial class fmrMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.btnSndKey = new System.Windows.Forms.Button();
this.btnStop = new System.Windows.Forms.Button();
this.timerSndKey = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// btnSndKey
//
this.btnSndKey.Location = new System.Drawing.Point(38, 34);
this.btnSndKey.Name = "btnSndKey";
this.btnSndKey.Size = new System.Drawing.Size(127, 42);
this.btnSndKey.TabIndex = 0;
this.btnSndKey.Text = "Send Key";
this.btnSndKey.UseVisualStyleBackColor = true;
this.btnSndKey.Click += new System.EventHandler(this.btnSndKey_Click);
//
// btnStop
//
this.btnStop.Enabled = false;
this.btnStop.Location = new System.Drawing.Point(171, 34);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(127, 42);
this.btnStop.TabIndex = 1;
this.btnStop.Text = "Stop";
this.btnStop.UseVisualStyleBackColor = true;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// timerSndKey
//
this.timerSndKey.Interval = 3000;
this.timerSndKey.Tick += new System.EventHandler(this.timerSndKey_Tick);
//
// fmrMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(344, 106);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.btnSndKey);
this.Name = "fmrMain";
this.Text = "Send Key";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnSndKey;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Timer timerSndKey;
}
}
[/highlight]
frmMain.cs
[highlight="C#"]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SendKeys
{
public partial class fmrMain : Form
{
public fmrMain()
{
InitializeComponent();
}
/// <summary>
/// Form loader. We have nothing to initialize upon
/// load. Blank.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
}
/// <summary>
/// This will start a timer that then sends
/// the key ~ every 3 seconds
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSndKey_Click(object sender, EventArgs e)
{
// Disable start button, enable stop button
btnSndKey.Enabled = false;
timerSndKey.Enabled = true;
btnStop.Enabled = true;
}
/// <summary>
/// This will stop the timer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStop_Click(object sender, EventArgs e)
{
// Disable start button, enable stop button
btnSndKey.Enabled = true;
timerSndKey.Enabled = false;
btnStop.Enabled = false;
}
/// <summary>
/// When the timer reaches 3000 ms (3 seconds) it will
/// execute this function which simply sends a key.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timerSndKey_Tick(object sender, EventArgs e)
{
System.Windows.Forms.SendKeys.Send("{~}");
}
}
}
[/highlight]
Program.cs
[highlight="C#"]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace SendKeys
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new fmrMain());
}
}
}
[/highlight]
This program loads a form with two buttons. When you press the "Send Key" button every 3 seconds the Tilda (~) key will be sent to the currently focused window. Pressing stop will stop the application.


Sign In
Create Account

Guest_Jordan_*


Back to top












