8

Does anyone know how to implement the standard bubble message that warns users whenever Caps Lock is enabled and a password control has focus? Is this built into the .NET framework, or do I need to write my own class to do this?

Adrian Toman
  • 11,316
  • 5
  • 48
  • 62
Rob Sobers
  • 20,737
  • 24
  • 82
  • 111
  • Did you solve this? I was looking for the same? – abmv Jun 25 '09 at 14:00
  • Follow: [How to give warning to user with balloon in wpf][1] [1]: http://stackoverflow.com/questions/1092808/wpf-warn-about-capslock/8060520#8060520 – NASSER Nov 09 '11 at 05:26
  • Use Keyboard.IsKeyToggled for CapsLock key and manually show tooltip or hint. – Vincent Jul 25 '19 at 12:55

3 Answers3

12

This is an old question, and already answered, but I came across this same problem and I first started with Keyboard.IsKeyToggled(Key.CapsLock) but that returned false if Caps Lock was set prior to the application running. So I found another solution that works perfectly.

Console.CapsLock //is boolean and returns true if CapsLock is on

Absolutely brilliant and simple (it's in the mscorlib dll so you don't have to worry about unneeded dependencies either)

Jose
  • 10,891
  • 19
  • 67
  • 89
3

You could add a handler function to the PasswordChanged event handler and test for the value of the CapsLock key in that function. If found to be on, you could pop-up a message from there.

xan
  • 7,440
  • 8
  • 43
  • 65
  • 4
    This will do the trick! To detect CapsLock in the event handler, just check the boolean value of: Keyboard.IsKeyToggled(Key.CapsLock) – Rob Sobers Sep 24 '09 at 20:02
  • This answer is useless: 1. PasswordChanged happen TOO LATE. Much better to react on 'GotFocus'. 2. HOW EXACTLY we can check status of CapsLock key? That was the question. – Vincent Jul 25 '19 at 12:21
2

If you use a MaskedTextBox and specify a passwordChar the .NET framework will automatically do this for you

Jaime Garcia
  • 6,744
  • 7
  • 49
  • 61
  • 4
    I believe MaskedTextBox is a WinForms control - I'm using WPF. I'd like to be able to continue using the PasswordBox because of its built-in security. – Rob Sobers Nov 26 '08 at 18:10