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("鍵盤處於小寫狀態!");
}