How to Detect CapsLock key using Java in NetBeansIDE.



How to Detect CapsLock key using Java in NetBeansIDE.

Note:
packages and classes used:

- java.awt.Toolkit;
- java.awt.event.KeyEvent;

1. Open NetBeansIDE.

2. Make a new project say DemoCaps.

3. Make a new JFrame Form in it say CapsLockDetect and design it.

4. RC on Form and Goto Properties~Events~KeyPressed~Select formKeyPressed.

5. Write the following code in the method and Fix all imports:

   if(Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK))
   {
       jLabel.setText("ON");
   }
   else
   {
       jLabel.setText("OFF");
   }

6. Run the Project.

7. Finish.

Thank You :)

Comments

  1. Thankyou very much.It helped me a lot.
    But the first line of code shows error as the braces are incomplete.Please correct it on your site.
    thanks once again.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Open a Text File with Notepad using JAVA in NetBeans

How to Perform DES Encryption and Decryption of TXT file in JAVA with NetBeansIDE