Handling Xbox One Media Remote in UWP applications

When you develop UWP application for Xbox One (Windows 10), you will probably need to optimize, how your app is controlable via Xbox One Media Remote.

If you see it for first time, Xbox One Media Remote is remote controller (based on IR), which you can buy from Microsoft Store for ~$25 as an offical Xbox accessory.

Buttons on Xbox One Media Remote

Xbox Media Controller - buttons

Handling pressed keys

In App.xaml.cs you have to change RequiresPointerMode:

   
 public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            this.RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
        }

   

There is example, how you can handle buttons on page:

   
public MainPage()
        {
            this.InitializeComponent();
            this.RequiresPointer = RequiresPointer.WhenEngaged;
            this.IsFocusEngagementEnabled = true;
            Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
        }

        private void CoreWindow_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
        {
            //let's play with args.VirtualKey
        }
   

Map remote’s buttons and VirtualKeys enum

Button Runtime equivalent
Home button (*) (VirtualKey)(7)
View button System.VirtualKey.GamepadView
Menu button System.VirtualKey.GamepadMenu
Navigation arrows System.VirtualKey.GamepadDPadLeft System.VirtualKey.GamepadDPadUp System.VirtualKey.GamepadDPadRight System.VirtualKey.GamepadDPadDown
Select button System.VirtualKey.GamepadA
Back button System.VirtualKey.GamepadB
OneGuide button not available during runtime
Volume+mute buttons not available during runtime
Channel buttons System.VirtualKey.PageUp System.VirtualKey.PageDown
Media control buttons not available during runtime
(*) Home button is special – when user press this button, Xbox opens system’s menu (you can’t override that), but system will also send you signal (VirtualKey)(7) – so for example, you can pause game or movie in your app.