Numlock Problem ?

Z

Z.K.

I am trying to detect if the Numlock is pressed. I can do it okay with
the CapsLock or the ScrLk, but not with NumLock. The code for all three
checks is exactly the same, but for some reason numlock always thinks it
is on.


Z.K.


code:

private void MainForm_KeyDown(object sender, KeyEventArgs e)
{

if (Control.IsKeyLocked(Keys.NumLock))
{
MessageBox.Show("The Num Lock key is ON.");
}
else
{
MessageBox.Show("The Num Lock key is OFF.");
}


if (Control.IsKeyLocked(Keys.CapsLock))
{
MessageBox.Show("The Caps Lock key is ON.");
}
else
{
MessageBox.Show("The Caps Lock key is OFF.");
}

if (Control.IsKeyLocked(Keys.Scroll))
{
MessageBox.Show("The Scroll Lock key is ON.");
}
else
{
MessageBox.Show("The Scroll Lock key is OFF.");
}


}
 
Z

Z.K.

Z.K. said:
I am trying to detect if the Numlock is pressed. I can do it okay with
the CapsLock or the ScrLk, but not with NumLock. The code for all three
checks is exactly the same, but for some reason numlock always thinks it
is on.


Z.K.


code:

private void MainForm_KeyDown(object sender, KeyEventArgs e)
{

if (Control.IsKeyLocked(Keys.NumLock))
{
MessageBox.Show("The Num Lock key is ON.");
}
else
{
MessageBox.Show("The Num Lock key is OFF.");
}


if (Control.IsKeyLocked(Keys.CapsLock))
{
MessageBox.Show("The Caps Lock key is ON.");
}
else
{
MessageBox.Show("The Caps Lock key is OFF.");
}

if (Control.IsKeyLocked(Keys.Scroll))
{
MessageBox.Show("The Scroll Lock key is ON.");
}
else
{
MessageBox.Show("The Scroll Lock key is OFF.");
}


}


Well, I found a way around the IsKeyLocked problem with NumLock. The
code is below though I still would like to know why IsKeyLocked does not
work with NumLock.

Z.K.

code:

String strLockText;

if(e.KeyCode == Keys.CapsLock)
{

//your code here
strLockText = stbStatusBarPanel3.Text;

if (strLockText.Contains("CAP"))
{
stbStatusBarPanel3.Text = "";

}
else
{
stbStatusBarPanel3.Text = "CAP";

}

}

else if(e.KeyCode == Keys.NumLock)
{

//your code here

strLockText = stbStatusBarPanel4.Text;

if (strLockText.Contains("NUM"))
{
stbStatusBarPanel4.Text = "";

}
else
{
stbStatusBarPanel4.Text = "NUM";

}


}

else if (e.KeyCode == Keys.Scroll)
{

strLockText = stbStatusBarPanel5.Text;

if (strLockText.Contains("SCRL"))
{
stbStatusBarPanel5.Text = "";

}
else
{
stbStatusBarPanel5.Text = "SCRL";

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top