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)) & 0xffff) != 0;
EDIT: the above is for framework 1.1, for framework 2.0 + you can use
Control.IsKeyLocked
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…