-1

I am developing an app for Windows 8.1

am using XAML + C#

I read the article this article in MSDN for Responding to keyboard interaction

I did as they say , but the problem is that the event occurs only when i press a key inside a TextBox

but i want the event to occur everywhere i press in the Page

Note: I use a laptop (no touch hardware)

XAML :

<Grid x:Name="GameGrid" Margin="0,0,0,0.111" KeyDown="Grid_KeyDown">

C# :

private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
 {
   if (e.Key == Windows.System.VirtualKey.A)
                    this.DoSomething();
 }
GabourX
  • 283
  • 2
  • 5
  • 14
  • @Cameron i want to handle the keypress everywhere on the page , like the whole `Page` , not a specefic `Grid` or something , the problem is that the event occurs only when i press the key inside a `TextBox` – GabourX Dec 10 '14 at 13:43
  • @Cameron Ofcourse i tried but i don't have a in my XAML , so i did it on the `Grid` that contains all the elements in the page – GabourX Dec 10 '14 at 13:53

1 Answers1

1

Try registering an accelerator key instead of a key event on grid (it must have focus to fire the event):

http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.core.coredispatcher.acceleratorkeyactivated

Example:

Window.Current.Dispatcher.AcceleratorKeyActivated += ...
Rico Suter
  • 11,548
  • 6
  • 67
  • 93