How to get the current state of Caps Lock using WinForms in C#

1 Answer

0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
    public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (IsKeyLocked(Keys.CapsLock))
            {
                MessageBox.Show("The Caps Lock key is ON");
            }
            else
            {
                MessageBox.Show("The Caps Lock key is OFF");
            }
        }
    }
}




/*
run:

The Caps Lock key is OFF
 
*/

 



answered Apr 29, 2024 by avibootz
edited Apr 29, 2024 by avibootz
...