Featured image of post Handling Xbox One Media Remote in UWP applications

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

Button description on Xbox One Media Remote

Handling pressed keys

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

1
2
3
4
5
6
7
 public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;

        this.RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
    }

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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
        }

Remote’s buttons and VirtualKeys enum mapping

ButtonRuntime equivalent
Home button (*)(VirtualKey)(7)
View buttonSystem.VirtualKey.GamepadView
Menu buttonSystem.VirtualKey.GamepadMenu
Navigation arrowsSystem.VirtualKey.GamepadDPadLeft
System.VirtualKey.GamepadDPadUp
System.VirtualKey.GamepadDPadRight
System.VirtualKey.GamepadDPadDown
Select buttonSystem.VirtualKey.GamepadA
Back buttonSystem.VirtualKey.GamepadB
OneGuide buttonnot available during runtime
Volume+mute buttonsnot available during runtime
Channel buttonsSystem.VirtualKey.PageUp System.VirtualKey.PageDown
Media control buttonsnot 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.

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy