How can I find the state of NumLock, CapsLock and ScrollLock keys in .NET?
Click on Screen Configurations tab. In Properties window, make sure Enable on-screen display is checked. Under "Indicator settings for NumLock and CapsLock" section, look for "While the numeric lock or caps lock is ON" section, choose the "Show the indicator for a few seconds" option.
How to tell whether Caps Lock is on. If you pressed the Caps Lock key, you can turn it off by pressing the key again. Many keyboards have a built-in status indicator that lights up when the Caps Lock key is on. This LED is located either directly on the key or on the status bar of the keyboard, if there is one.
To turn on the Num Lock function, press the Num Lock key until you see the LED (light) above it turn on. Likewise, to turn it off, press the Num Lock key until the LED goes out. Once the Num Lock key is pressed, it stays on until it is pressed again.
Num Lock or Numeric Lock (⇭) is a key on the numeric keypad of most computer keyboards. It is a lock key, like Caps Lock and Scroll Lock. Its state affects the function of the numeric keypad commonly located to the right of the main keyboard and is commonly displayed by a LED built into the keyboard.
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 this:
bool CapsLock = (((ushort)GetKeyState(0x14)) & 0xffff) != 0; bool NumLock = (((ushort)GetKeyState(0x90)) & 0xffff) != 0; bool ScrollLock = (((ushort)GetKeyState(0x91)) & 0xffff) != 0;
It is for framework 1.1. For framework 2.0 (and later) you can use:
Control.IsKeyLocked
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With