I'm writing a VNC client for HoloLens using C# and I'm having a tough time figuring out how to handle keyboard input. KeyUp/KeyDown give me a Windows.System.VirtualKey object, but there doesn't appear to be an API to map these VirtualKeys (along with modifiers, e.g. shift) to the characters they represent on a given layout. E.g. VirtualKey.Shift + VirtualKey.F == 'F' versus 'f' when it's simply VirtualKey.F. Or Shift + 5 to give % on a US keyboard.
In win32 apps you'd use MapVirtualKey to handle the keyboard layout for you -- how does this get handled in UWP?
It is not possible to get the translated character in KeyUp/KeyDown events. But it is possible when using CoreWindow.CharacterReceived event to get the translated character.
You can register the event by the following codes:
Window.Current.CoreWindow.CharacterReceived += CoreWindow_CharacterReceived;
And you will get a KeyCode of the translated input character(e.g. for shift+5
it gets 37
, while for 5
it gets 53
) through the CharacterReceivedEventArgs:
private void CoreWindow_CharacterReceived(CoreWindow sender, CharacterReceivedEventArgs args)
{
uint keyCode=args.KeyCode;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With