ok, I got it working, here is what I did
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Text;
namespace ACAD_CapsLockUtil
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
#region Windows Form Designer generated code
private System.ComponentModel.IContainer components;
public frmMain()
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <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();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
this.niMain = new System.Windows.Forms.NotifyIcon(this.components);
this.niMenu = new System.Windows.Forms.ContextMenu();
this.miPauseStart = new System.Windows.Forms.MenuItem();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.lblAbout = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.btnOK = new System.Windows.Forms.Button();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// niMain
//
this.niMain.ContextMenu = this.niMenu;
this.niMain.Icon = ((System.Drawing.Icon)(resources.GetObject("niMain.Icon")));
this.niMain.Text = "TEP AutoCad CapsLock Utility";
this.niMain.Visible = true;
//
// niMenu
//
this.niMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miPauseStart,
this.menuItem1,
this.menuItem2});
//
// miPauseStart
//
this.miPauseStart.Index = 0;
this.miPauseStart.Text = "Pause";
this.miPauseStart.Click += new System.EventHandler(this.miPauseStart_Click);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// lblAbout
//
this.lblAbout.Location = new System.Drawing.Point(48, 8);
this.lblAbout.Name = "lblAbout";
this.lblAbout.Size = new System.Drawing.Size(232, 32);
this.lblAbout.TabIndex = 0;
this.lblAbout.Text = "About";
this.lblAbout.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(32, 32);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(264, 168);
this.label1.TabIndex = 2;
this.label1.Text = "label1";
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(112, 232);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 3;
this.btnOK.Text = "OK";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Text = "-";
//
// menuItem2
//
this.menuItem2.Index = 2;
this.menuItem2.Text = "Help";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.ControlBox = false;
this.Controls.Add(this.btnOK);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.lblAbout);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "frmMain";
this.Text = "TEP AutoCad CapsLock Utility";
this.Load += new System.EventHandler(this.frmMain_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.frmMain_Paint);
this.ResumeLayout(false);
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}
private System.Windows.Forms.NotifyIcon niMain;
private System.Windows.Forms.ContextMenu niMenu;
private System.Windows.Forms.MenuItem miPauseStart;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label lblAbout;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
#endregion
const byte VK_CAPITAL=0x14;
string ActiveAppTitle = "Rob H. Needs A Raise Without Any Added Responsibilities";
bool Initial = false;
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
[ DllImport("user32.dll") ]
static extern int GetForegroundWindow();
[ DllImport("user32.dll") ]
static extern int GetWindowText(int hWnd, StringBuilder text, int count);
[DllImport("user32.dll")]
public static extern short GetKeyState(int nVirtKey);
private void ToggleKey(byte KeyCode)
{
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
keybd_event(KeyCode, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr) 0);
keybd_event(KeyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr) 0);
}
private void miPauseStart_Click(object sender, System.EventArgs e)
{
if (timer1.Enabled)
{
timer1.Enabled = false;
miPauseStart.Text = "Re-Start";
}
else
{
timer1.Enabled = true;
miPauseStart.Text = "Pause";
}
}
private void frmMain_Load(object sender, System.EventArgs e)
{
lblAbout.Text = "This program was created for TEP \n by Robert Houts and David Hall";
label1.Text = "This program was created to ensure that the caps lock key is enabled while you are working in AutoCAD. When AutoCAD is the active window, it will turn the Caps Lock key On and when you leave AutoCAD, it will turn Caps Lock Off. \n\nKeep in mind, you can still manually toggle the Caps Lock key on your own and you can pause this program by right-clicking the 'C' icon and selecting 'Pause'. You re-enable this program by right-clicking the 'C' icon and selecting 'Re-Start'. \n\nThank you and Happy Drafting! :-)";
}
private void btnOK_Click(object sender, System.EventArgs e)
{
this.Hide();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.Visible = true;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
string CurrentTitle = GetActiveWindowTitle();
if (ActiveAppTitle != CurrentTitle)
{
if (CurrentTitle.StartsWith("AutoCAD "))
{
if (GetKeyState(VK_CAPITAL) == 0)
{
ToggleKey(VK_CAPITAL);
}
}
else
{
if (GetKeyState(VK_CAPITAL) == 1)
{
ToggleKey(VK_CAPITAL);
}
}
}
ActiveAppTitle = CurrentTitle;
CurrentTitle = string.Empty;
}
private string GetActiveWindowTitle()
{
const int nChars = 256;
int handle = 0;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();
if ( GetWindowText(handle, Buff, nChars) > 0 )
return Buff.ToString();
else
return string.Empty;
}
private void frmMain_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (Initial == false)
{
this.Hide();
Initial = true;
}
}
}
}