本文實例講述了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("鍵盤處于大寫鎖定狀態!");elseMessageBox.Show("鍵盤處于小寫狀態!");}
希望本文所述對大家的C#程序設計有所幫助。
新聞熱點
疑難解答