Home > Silverlight 5 > Finding Key State using PInvoke in SL5 RC

Finding Key State using PInvoke in SL5 RC

September 19, 2011 Leave a comment Go to comments

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;

 

 

About these ads
Categories: Silverlight 5

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: