How to Check Caps Lock State Before Password in C++

The Program will generate a warning that Caps Lock is ON before entering the Password. GetkeyState function which is part of Windows API is used to detect the state of Caps Lock key. GetkeyState function retrieves the state of different keys.

Source Code

#include<iostream>
#include<windows.h>
using namespace std;
int main ()
{ 
  string name;
  string password;
  cout<<" \t \t \t LEP Tutorials \n \n \n ";
  cout<<" Enter Your Name : ";
  
  cin>>name;
  if ((GetKeyState(VK_CAPITAL) & 0x0001)!=0)
      {
      
   cout<<(" \t \n  WARNING! Caps Lock ON \n \n ");
  cout<<" Enter Password  : ";
  
}
  cin>>password;
}

Output of the Program

Caps Lock State check before Password in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment