How do I capture a keyboard shortcut, no matter which control has focus? I don't want to go and write the same thing for each possible control that the user could give focus to. So how can I watch for a page-wide/control-independent shortcut?
Add this code to the constructor it will handle a global key down and key
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
Window.Current.CoreWindow.KeyUp += CoreWindow_KeyUp;
heres their events
void CoreWindow_KeyUp(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
{
//this.Frame.Navigate(typeof(MainPage));
var key = args.VirtualKey;
string aa = args.ToString();
}
void CoreWindow_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
{
//this.Frame.Navigate(typeof(MainPage));
var key = args.VirtualKey;
string aa = args.ToString();
}
you can ahndle your own logic inside this event.
How about setting an event handler at the root element? I think event will eventually reach the parent control, if it is not handled anywhere else. Here's what I would do for a simple KeyDown event.
<common:LayoutAwarePage
x:Name="pageRoot"
//elided
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" KeyDown="MyEventHandler">
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