473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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_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.");
}
}
Sep 28 '08 #1
3 3922
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_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";

}

}
Sep 28 '08 #2
Thanks for letting us know the solution - very useful.

SteveT
Sep 28 '08 #3
Steve Thackery wrote:
Thanks for letting us know the solution - very useful.

SteveT
Glad to help.

Z.K.
Sep 28 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: George | last post by:
Every time I used the Sendkeys command in my application the "Numlock" turned off and I couldn't use the keypad to hit numbers...... The old code was: Private Sub Command1_Click() SendKeys...
5
by: James Kirkup | last post by:
Hello, Does anyone know in code how to turn the NumLock key on in C#? with regards James *** Sent via Developersdex http://www.developersdex.com ***
2
by: Chris | last post by:
can anyone out there tell me how do u check the state of these keys in vb.net? or is there any components in the .NET Framework that supports doing so? any help is appreciated. Thanks.
2
by: Woody Splawn | last post by:
Could someone tell me what code I run to determine if the user's numlock is on? Is there code I can run to set the numlock to on?
5
by: Stan Sainte-Rose | last post by:
Hi I saw a post about numlock but I can't not read it. I would like to check the state of the numlock key and if it's not active, set its status on active. How can I accomplish that in vb ? ...
1
by: nTn | last post by:
I'd like show in my status bar, status of NumLock, CapsLock and ScrollLock. How I do? Thx
10
by: lgbjr | last post by:
Hi All, In VB.Net how do I determine if CapsLock is on/off (same for NumLock) and whether the input mode is set to Insert or Overwrite (Insert Key). I just added a status bar to my app, and I...
0
by: =?Utf-8?B?Q29tcHV0ZXJfRW5naW5lZXJfU3R1ZGVudA==?= | last post by:
I'm locking for an C# equivalent to the VBS code On Error Resume Next Set objWord = CreateObject("Word.Application", "" & txtPCName.Value & "") strCapsLock = objWord.CapsLock strNumLock =...
0
by: Yusuf Incekara | last post by:
I 've assigned a shortcut key for CTRL+SHIFT+1 key in my application. I can handle these keys in Form's keydown event. private void Form1_Load(object sender, EventArgs e) { this.KeyPreview =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.