Open E-School

Male
Friday, February 24, 1984

Console.NumberLock - Checking the status of the num lock key using C#

Category: Programming Date: Sunday, March 22, 2015

Goal – Check the status of the num 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.NumberLock– A static readonly property of the Console class.

Brief description

Console.NumberLock property tells us if the num 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 num lock key, you cannot turn it on or off

Code

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

Output

When the num lock key is not pressed on the keyboard

Console.NumLock output

Explanation of the code

In the code we have an if else statement to check the value of the NumberLock key on the keyboard. If the NumberLock 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.NumberLock property is a read only property. You cannot turn the NumberLock 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

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