Click here to Skip to main content
13,629,406 members
Click here to Skip to main content
Add your own
alternative version

Stats

15.4K views
8 downloads
13 bookmarked
Posted 24 Jun 2013
Licenced CPOL

A Simple Application to Notify the Caps Lock Status

, 25 Jun 2013
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180712.1 | Last Updated 25 Jun 2013
Article Copyright 2013 by Kaushik S Murthy
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid