Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A Simple Application to Notify the Caps Lock Status

0.00/5 (No votes)
25 Jun 2013 1  
This application allows you to know the status of caps lock whenever the caps status is toggled

Introduction

We all have at one time or another used a keyboard which does not have the LED indicator for showing the status of caps lock, num lock, etc. The caps is especially a problem because it causes us to type the wrong password many times. This application provides a indicator of whether caps is on or off whenever the state of caps lock changes.

Using the Code

The first thing that needs to be mentioned is that I have used the TaskbarNotifier which can be found here for the purpose of showing the popup. Any instructions which are required to use the TaskbarNotifier can be found in the above link. I have used a timer to periodically check the status of caps lock and show the status whenever a change is detected. The static values declared in vars are used to check if the status is changed or not.

// public static class vars
        {
            public static string prevstate = "off";
            public static string curstate = "off";
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            
            if (Control.IsKeyLocked(Keys.CapsLock))
            {
                vars.prevstate = vars.curstate;
                vars.curstate = "on";
                if(vars.prevstate != vars.curstate)
                {
                TaskbarNotifier taskbarNotifier1;
                taskbarNotifier1 = new TaskbarNotifier();
                taskbarNotifier1.SetBackgroundBitmap(new Bitmap(GetType(), 
                "skin.bmp"), Color.FromArgb(255, 0, 255));
                taskbarNotifier1.SetCloseBitmap(new Bitmap(GetType(), 
                "close.bmp"), Color.FromArgb(255, 0, 255), new Point(127, 8));
                taskbarNotifier1.TitleRectangle = new Rectangle(40, 9, 100, 25);
                taskbarNotifier1.ContentRectangle = new Rectangle(8, 41, 150, 68);
                taskbarNotifier1.Show("Caps Lock status", 
                "Caps Lock key is ON", 500, 500, 500);
                }
            }
            else if (!(Control.IsKeyLocked(Keys.CapsLock)))
            {
                vars.prevstate = vars.curstate;
                vars.curstate = "off";
                if (vars.prevstate != vars.curstate)
                {
                    TaskbarNotifier taskbarNotifier1;
                    taskbarNotifier1 = new TaskbarNotifier();
                    taskbarNotifier1.SetBackgroundBitmap(new Bitmap(GetType(), 
                    "skin.bmp"), Color.FromArgb(255, 0, 255));
                    taskbarNotifier1.SetCloseBitmap(new Bitmap(GetType(), 
                    "close.bmp"), Color.FromArgb(255, 0, 255), new Point(127, 8));
                    taskbarNotifier1.TitleRectangle = new Rectangle(40, 9, 100, 25);
                    taskbarNotifier1.ContentRectangle = new Rectangle(8, 41, 150, 68);
                    taskbarNotifier1.Show("Caps Lock status", 
                    "Caps Lock key is OFF", 500, 500, 500);
                }
            }
        }

Also, in the form load event, I have made sure that the application runs on taskbar and does not interfere by showing any window. The code used for this purpose is:

 if (FormWindowState.Minimized == this.WindowState)
            {
                mynotifyicon.BalloonTipText = 
                	"This app shows a notification whenever caps key is pressed ";
                
                mynotifyicon.BalloonTipTitle = "Caps Lock Indicator";
                 
                mynotifyicon.Visible = true;
                mynotifyicon.ShowBalloonTip(500);
                this.Hide();
            }
            else if (FormWindowState.Normal == this.WindowState)
            {
                mynotifyicon.Visible = false;  
            } 

Also, in the form load event, I have made sure that the application runs on taskbar and does not interfere by showing any window by setting the always start in minimized mode form's property. Add the executable file to the startup folder to make sure that the app runs every time a user logs in. Finally, I would like to thank the John O'Byrne for writing and making available to us TaskbarNotifier which made writing code for this app a breeze.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here