Detect the Capslock status on Windows keyboard

Is there an easy way to detect the Capslock status in a desktop app.
I need to know if CapsLock is ON or OFF on the computer when I start my app.


There may be a more X-PLAT way to do this but the following works on windows:

#if TargetWin32 declare Function GetKeyState lib "User32" (key as Integer) as Integer If (GetKeyState(&h14) > 0) then Label1.Text = "Caps On" Else label1.text = "Caps off" End If #endif

Thanks Jim. This works great.

Next question - How can I switch CapsLock OFF (or ON)


This might work for you.

#if TargetWin32 Declare Sub keybd_event Lib "User32" (ByVal vk as Byte, ByVal sc as Byte, ByVal flags as Integer, extinfo as Integer) //Toggle caps lock keybd_event(&h14, &h14, 1,0) //simulate press and release keybd_event(&h14, &h14, 3,0) #endif