Numlock Problem ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Z.K.

    Numlock Problem ?

    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_KeyDow n(object sender, KeyEventArgs e)
    {

    if (Control.IsKeyL ocked(Keys.NumL ock))
    {
    MessageBox.Show ("The Num Lock key is ON.");
    }
    else
    {
    MessageBox.Show ("The Num Lock key is OFF.");
    }


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

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


    }
  • Z.K.

    #2
    Re: Numlock Problem ?

    Z.K. wrote:
    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_KeyDow n(object sender, KeyEventArgs e)
    {
    >
    if (Control.IsKeyL ocked(Keys.NumL ock))
    {
    MessageBox.Show ("The Num Lock key is ON.");
    }
    else
    {
    MessageBox.Show ("The Num Lock key is OFF.");
    }
    >
    >
    if (Control.IsKeyL ocked(Keys.Caps Lock))
    {
    MessageBox.Show ("The Caps Lock key is ON.");
    }
    else
    {
    MessageBox.Show ("The Caps Lock key is OFF.");
    }
    >
    if (Control.IsKeyL ocked(Keys.Scro ll))
    {
    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 = stbStatusBarPan el3.Text;

    if (strLockText.Co ntains("CAP"))
    {
    stbStatusBarPan el3.Text = "";

    }
    else
    {
    stbStatusBarPan el3.Text = "CAP";

    }

    }

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

    //your code here

    strLockText = stbStatusBarPan el4.Text;

    if (strLockText.Co ntains("NUM"))
    {
    stbStatusBarPan el4.Text = "";

    }
    else
    {
    stbStatusBarPan el4.Text = "NUM";

    }


    }

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

    strLockText = stbStatusBarPan el5.Text;

    if (strLockText.Co ntains("SCRL"))
    {
    stbStatusBarPan el5.Text = "";

    }
    else
    {
    stbStatusBarPan el5.Text = "SCRL";

    }

    }

    Comment

    • Steve Thackery

      #3
      Re: Numlock Problem ?

      Thanks for letting us know the solution - very useful.

      SteveT

      Comment

      • Z.K.

        #4
        Re: Numlock Problem ?

        Steve Thackery wrote:
        Thanks for letting us know the solution - very useful.
        >
        SteveT
        Glad to help.

        Z.K.

        Comment

        Working...