Open In App

C# | Check if Num Lock is on or off through Console

Last Updated : 28 Jan, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

Given the normal Console in C#, the task is to check if the NUM LOCK is on or off through Console.

Approach: This can be done using the NumberLock property in the Console class of the System package in C#. This property gets a value indicating whether the NUM LOCK keyboard toggle is turned on or turned off.

Program 1: When the NUM LOCK is on




// C# program to illustrate the
// Console.NumberLock Property
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
  
namespace GFG {
  
class Program {
  
    static void Main(string[] args)
    {
  
        // Check if NUM LOCK is on or off
        Console.WriteLine("Is NUM LOCK on: {0}",
                          Console.NumberLock);
    }
}
}


Output:

Program 2: When the NUM LOCK is off




// C# program to illustrate the
// Console.NumberLock Property
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
  
namespace GFG {
  
class Program {
  
    static void Main(string[] args)
    {
  
        // Check if NUM LOCK is on or off
        Console.WriteLine("Is NUM LOCK on: {0}",
                          Console.NumberLock);
    }
}
}


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads