How to get the current state of Num 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.NumLock))
            {
                MessageBox.Show("The Num Lock key is ON");
            }
            else
            {
                MessageBox.Show("The Num Lock key is OFF");
            }
        }
    }
}




/*
run:

The Num Lock key is ON
 
*/

 



answered Apr 29, 2024 by avibootz
...