How can I find the state of NumLock, CapsLock and ScrollLock in .net?
问题 How can I find the state of NumLock, CapsLock and ScrollLock keys in .net ? 回答1: Import the WinAPI function GetKeyState [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] public static extern short GetKeyState(int keyCode); and then you can use it like that bool CapsLock = (((ushort)GetKeyState(0x14)) & 0xffff) != 0; bool NumLock = (((ushort)GetKeyState(0x90)) & 0xffff) != 0; bool ScrollLock = (((ushort)GetKeyState(0x91)) &