判断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);
        }

  

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10289956.html