Question

In a Silverlight application's log in screen, i need to determine if Caps Lock is toggled. This is easy enough by handling the KeyUp or KeyDown event, however how does one determine if it is toggled on or off even if a key hasn't been pressed?

The reason I want todo this is what if the user doesn't press Caps Lock while the Silverlight application is running, but rather they toggled it before they even got to the login screen? I need to still warn them that caps Lock is on.

Apparently handling unmanaged code is not possible in Silverlight so the following doesn't work.

[DllImport("user32.dll")] internal static extern short GetKeyState(int keyCode);

Was it helpful?

Solution

The way to detect CAPS LOCKS is to check the KeyValue and the Shift of KeyEventArgs.
if the KeyValue is (for example) 'A' but the Shift is false then the CAPS LOCKS is on.
Not the best way but its how ajax applications has been doing it.

OTHER TIPS

As far as I know you can't. You might be able to pickup on the key going up and down from your app, but you won't know what state it was in if the users leave your app.

I've not noticed any additional supprt for it in SL3, but I can't say I've been particularly looking for it.

Silverlight does not support invoking Win32 DLLs on the client side. So you can't use the above technique to test whether the Capslock key is pressed. Have you tried using the KeyDown event and testing for System keys? I haven't done that, but it's a hunch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top