C# 判断大小写是否按下

原文:https://blog.csdn.net/z397164725/article/details/7377815 

测试确实可以!

1.//鼠标在UI移动才能获取,不建议使用
        [DllImport("user32.dll", EntryPoint = "GetKeyboardState")]

        public static extern int GetKeyboardState(byte[] pbKeyState);

//大小写状态

         byte[] bs = new byte[256];
         GetKeyboardState(bs);
         if(bs[0x14] == 1);
 {
                MessageBox.Show("按下"); 
 }

2.
        [DllImport("USER32", SetLastError = true)]
        static extern short GetKeyState(int nVirtKey);

      //大小写状态
        if (GetKeyState(20) == 1)
            {
                MessageBox.Show("按下");
            }

3.
      //大小写状态
        if (IsKeyLocked(Keys.CapsLock))
            {
                MessageBox.Show("按下");

            }
 

猜你喜欢

转载自blog.csdn.net/xionglifei2014/article/details/84957617
今日推荐