如何在.NET中找到NumLock,CapsLock和ScrollLock键的状态?
导入WinAPI函数GetKeyState
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] public static extern short GetKeyState(int keyCode);
然后你可以像那样使用它
bool CapsLock = (((ushort)GetKeyState(0x14)) & 0xffff) != 0; bool NumLock = (((ushort)GetKeyState(0x90)) & 0xffff) != 0; bool ScrollLock = (((ushort)GetKeyState(0x91)) & 0xffff) != 0;
编辑:以上内容适用于框架1.1,适用于框架2.0 +
Control.IsKeyLocked