on is asctive or not ... how to find out if caplock is active or not
-
Hi i am inetrested in finding out if the caplock button is active or not ... Thats when the form loads... or if there is a way to like toggle the button to disable when it loads ... Thanks DaIn
-
Hi i am inetrested in finding out if the caplock button is active or not ... Thats when the form loads... or if there is a way to like toggle the button to disable when it loads ... Thanks DaIn
P/Invoke the native function
GetKeyState
:[DllImport("user32.dll")]
private static extern short GetKeyState(int virtKey);You would then pass 20 (
VK_CAPITAL
) to get the CAPS LOCK key state. Fortunately (for good reason), theSystem.Windows.Forms.Keys
enumeration members match up with the virtual key constants defined in winuser.h, so you can use(int)Keys.CapsLock
instead for more readable code:short value = GetKeyState((int)Keys.CapsLock);
bool on = (value & 0x0001) != 0;
myButton.Enabled = !on;It's important to mask out the high-order bit so you can check the status of the low-order bit. This is documented in the Platform SDK documentation for the
GetKeyState
, see so that for more information.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----