Open E-School

Male
Friday, February 24, 1984

Console.CapsLock - Checking the status of the caps lock key using C#

Category: Programming Date: Sunday, March 22, 2015
OpenESchool Emagazine

Goal – Check the status of the caps lock key using C# console application

Namespaces used

System ( Console class is defined in the System namespace )

Classes used

Console – This class handles all the console related operations in C#

Properties used

Console.CapsLock – A static readonly property of the Console class.

Brief description

Console.CapsLock property tells us if the caps lock key is pressed on the keyboard or not. This is a read only property, which means that you can only check the status of the caps lock key, you cannot turn it on or off

Code

using System;    namespace DBApplication  {      class Program      {          public static void Main(string[] args)          {              if (Console.CapsLock)                  Console.WriteLine("Your caps lock key is on");              else                  Console.WriteLine("Your caps lock key is off");          }      }  }

Output

When the caps lock key is not pressed on the keyboard

Console.CapsLock output when the caps lock is not turned on

When the caps lock key is pressed on the keyboard

Console.CapsLock status when the caps lock key is turned on

Explanation of the code

In the code we have an if else statement to check the value of the CapsLock key on the keyboard. If the capslock key is on you will see the output from the if block and if it is off then you will see the output from the else block

Special remarks

Please keep in mind that Console.CapsLock property is a read only property. You cannot turn the caps lock key on or off by using this property.

Rate this article and help us improve

Please Login to rate
Overall ratings: 0 | Rating: out of 5
Previous Article Next Article

Posted By

Open E-School
Member since : 2015-01-09
Total points : 3375

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp