Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Checking for CAPS LOCK key enabled or not in C#

With Console.CapsLock we detect whether caps lock is enabled on the computer.
This property cannot be assigned.
If you need to turn caps lock off, you will need to instruct the keyboard user to press it again.

The Console.CapsLock property could be used in several different ways. If a program is requiring a password to be entered, you could print an error message if caps lock is pressed and the password is incorrect.

  1. using System;
  2. using System.Threading;
  3.  
  4. namespace forgetCode
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. Thread.Sleep(1000);
  11. bool capsLock = Console.CapsLock;
  12. Console.WriteLine(capsLock);
  13. }
  14.  
  15. }
  16. }


Output:
True or false (depending on the caps lock key pressed on computer)

..