.net2.0轻松判断NumLock、CapsLock、ScrollLock、Insert键的状态:)
不多说了,直接插代码:) 不用Api
public Form1()
{
InitializeComponent();
Application.Idle += new EventHandler(Application_Idle);
}
private void Application_Idle(object sender, EventArgs e)
{
if (Control.IsKeyLocked(Keys.NumLock))
labelNumLock.Text = "ON";
else
labelNumLock.Text = "OFF";
if (Control.IsKeyLocked(Keys.CapsLock))
labelCapsLock.Text = "ON";
else
labelCapsLock.Text = "OFF";
if (Control.IsKeyLocked(Keys.Scroll))
labelScrollLock.Text = "ON";
else
labelScrollLock.Text = "OFF";
if (Control.IsKeyLocked(Keys.Insert))
labelInsert.Text = "ON";
else
labelInsert.Text = "OFF";
}
郁闷,我的博客出了BUG。
{
InitializeComponent();
Application.Idle += new EventHandler(Application_Idle);
}
private void Application_Idle(object sender, EventArgs e)
{
if (Control.IsKeyLocked(Keys.NumLock))
labelNumLock.Text = "ON";
else
labelNumLock.Text = "OFF";
if (Control.IsKeyLocked(Keys.CapsLock))
labelCapsLock.Text = "ON";
else
labelCapsLock.Text = "OFF";
if (Control.IsKeyLocked(Keys.Scroll))
labelScrollLock.Text = "ON";
else
labelScrollLock.Text = "OFF";
if (Control.IsKeyLocked(Keys.Insert))
labelInsert.Text = "ON";
else
labelInsert.Text = "OFF";
}