The best way to handle this is to use the Window_TextInput event rather than KeyDown.
But, as you said, this event does not fire in your application, you can use the hack like this:
bool iscapsLock = false; bool isShift = false; private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.CapsLock) iscapsLock = !iscapsLock; if (e.Key >= Key.A && e.Key <= Key.Z) { bool shift = isShift; if (iscapsLock) shift = !shift; int s = e.Key.ToString()[0]; if (!shift) { s += 32; } Debug.Write((char)s); } }
This will print the characters correctly, depending on whether the hood is on or not. The initial value of Capslock can be obtained using this link:
http://cboard.cprogramming.com/csharp-programming/105103-how-detect-capslock-csharp.html
Hope this works for you.
source share