0

I'm using WPF with vb.net. I want to capture a key press event of the '#' key. I'm using a german keyboard. But I wont this to work with different language settings.

Private Sub textbox_KeyDown(sender As Object, e As KeyEventArgs) Handles texbox.KeyDown
        If e.Key.ToString() = "#" Then
            'do stuff
        End If
End Sub

e.Key.ToString() returns "OemQuestion"

Chr(e.key) returns "‘"

ChrW(e.key) returns ChrW(145)

The ASCII code for '#' is 35.

So would I do this?

Bil_Bomba
  • 183
  • 1
  • 8

1 Answers1

0

For an English keyboard (not sure if this is the same for a German keyboard, sorry), since '#' is entered by pressing Shift + 3 you would need to compare the e.Key argument to a Key enum while checking for a modifier (it's C#, but should be easy to translate to VB):

if(e.Key == Key.D3 && Keyboard.IsKeyDown(Key.LeftShift))
{

}

D3 is for the key corresponding to the number 3 and you can also check to see if the left or right shift key is pressed. e.Key.ToString() doesn't return the string value of the key that was pressed.

Jay T
  • 853
  • 10
  • 11
  • On the German keyboard I dont need shift for '#'. So this solution wont work. So obviously I cannot use the keycode, as it varys with the language setting. – Bil_Bomba Feb 05 '16 at 06:53
  • Will this help? http://stackoverflow.com/questions/5825820/how-to-capture-the-character-on-different-locale-keyboards-in-wpf-c – Jay T Feb 05 '16 at 16:33