Finding Key State using PInvoke in SL5 RC
If we have to find the Key State of CAPS lock, NUM lock etc in silverlight 5 RC, we could do like this using PInvoke
Add the Declaration
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern short GetKeyState(int keyCode);
And to get the different Key states
bool CapsLock = (((ushort)GetKeyState(0×14)) & 0xffff) != 0;
bool NumLock = (((ushort)GetKeyState(0×90)) & 0xffff) != 0;
bool ScrollLock = (((ushort)GetKeyState(0×91)) & 0xffff) != 0;
Advertisement
Categories: Silverlight 5