实现效果:

  判断NumLock键和CapsLock键是否被锁定

知识运用:

  AIP函数GetKeyState    //针对已处理过的按键 在最近一次输入信息时 判断指定虚拟键的状态

    intkey:预测试的虚拟键键码

实现代码:

        [DllImport("user32.dll",EntryPoint="GetKeyState")]
        public extern static int GetKeyState(int intkey);
        private void button1_Click(object sender, EventArgs e)
        {
            string str="判断NumLock键和CapsLock键是否被锁定:\n";
            int intCapsLock=GetKeyState(20);
            if(intCapsLock==0)
            {
                str+="CapsLock键没有被锁定\n";
            }else
            {
                str+="CapsLock键已经被锁定\n";
            }
            int intNumLock=GetKeyState(145);
            if (intNumLock == 0)
            {
                str+="NumLock键没有被锁定\n";
            }else
            {
                str+="NumLock键已经被锁定\n";
            }
            MessageBox.Show(str,"提示",MessageBoxButtons.OK);
        }

  

相关文章:

  • 2022-12-23
  • 2022-02-26
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案