Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Check State of CapsLock Button with C# in Windows Store (WinRT) Application

I'm trying to put a flyout warning if CapsLock button is On while typing something in PasswordBox.

I'm NOT trying to find out if the pressed key is CapsLock

I checked out the old,

KeyboardDevice .NET 3.5

Control.IsKeyLocked() Windows Forms

Console.CapsLock Not Available in Windows 8.1 Store Application

Keyboard.GetKeyStates Not Available in Windows 8.1 Store Application

and WinApi Style calls.

None of them seems suitable, Anyone has a suggestion

like image 204
accfews Avatar asked Nov 04 '13 18:11

accfews


1 Answers

Try CoreWindow.GetAsyncKeyState with a value of VirtualKey.CapitalLock.

You can get the current CoreWindow with CoreWindow.GetForCurrentThread.

Additionally, you can subscribe to the CoreWindow.KeyDown and CoreWindow.KeyUp events to update your key status indicator.

like image 108
Peter Huene Avatar answered Nov 15 '22 01:11

Peter Huene