Working with VirtualKey on Windows 8 with C # Applications

I know how to handle key events, i.e.

private void Page_KeyUp(object sender, KeyRoutedEventArgs e) { switch (e.Key) { case Windows.System.VirtualKey.Enter: // handler for enter key break; case Windows.System.VirtualKey.A: // handler for A key break; default: break; } } 

But what if I need to distinguish between lower case "a" and upper case "A"? Also, what if I want to process keys, such as the percent sign "%"?

+6
source share
2 answers

Got a response elsewhere. For those who are interested ...

 public Foo() { this.InitializeComponent(); Window.Current.CoreWindow.CharacterReceived += KeyPress; } void KeyPress(CoreWindow sender, CharacterReceivedEventArgs args) { args.Handled = true; Debug.WriteLine("KeyPress " + Convert.ToChar(args.KeyCode)); return; } 

Even better, move Window.Current.CoreWindow.CharacterReceived += KeyPress; in the GotFocus event handler and add Window.Current.CoreWindow.CharacterReceived -= KeyPress; to the LostFocus event handler.

+8
source

You cannot easily get this information from KeyUp , because KeyUp only knows which keys are pressed and not which letters are printed. You can verify that the toggle key is pressed, and you can also try to track the lock of the buttons. You better use the TextChanged event.

+1
source

Source: https://habr.com/ru/post/945977/


All Articles