C#检查键盘大小写锁定状态的方法


本文实例讲述了C#检查键盘大小写锁定状态的方法。分享给大家供大家参考。具体分析如下:

1、命名空间:

using System.Runtime.InteropServices;

2、导入方法

[DllImport("user32.dll", EntryPoint = "GetKeyboardState")]
public static extern int GetKeyboardState(byte[] pbKeyState);

3、大小写状态

public static bool CapsLockStatus
{
get
{
byte[] bs = new byte[256];
GetKeyboardState(bs);
return (bs[0x14] == 1);
}
}

4、引用,此部分根据你的需要来修改

private void button2_Click(object sender, EventArgs e)
{
if (CapsLockStatus == true)
MessageBox.Show("键盘处于大写锁定状态!");
else
MessageBox.Show("键盘处于小写状态!");
}

希望本文所述对大家的C#程序设计有所帮助。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3