Share via


Windows XP Media Center Edition SDK Navigation Using the Remote Control Device 

banner art
Previous Next

Navigation Using the Remote Control Device

Because users of Media Center applications may not have ready access to a keyboard and mouse, they may rely on the UP, DOWN, LEFT, and RIGHT arrows of the remote control for navigation within a page, and the OK button to activate selections. The arrows enable the user to switch the focus between selectable elements, but not to move about the page freely as if using a mouse. This limited movement capability may seem restrictive, but the portability and simplicity of the remote control can be a great convenience to the user as long as applications are designed to make navigation streamlined and intuitive. It is important that the user always knows which selectable element the focus is on, and where the focus will go next in response to any button click.

To handle remote control key presses, you create a script function called onRemoteEvent. When the user presses a navigation button on the remote control, Media Center calls your application's implementation of the onRemoteEvent event handler function. When pressed, each button sends an identifying number to the computer. This identifier is passed as the keychar parameter to the onRemoteEvent function, which you can use to call other functions based on the button that was pressed.

The following JScript code shows a sample implementation of the onRemoteEvent function.

  

When onRemoteEvent returns true, Media Center does not handle the user input, though the input may still be handled by the HTML application. Returning ** false ** indicates that Media Center should handle the user input wherever it has built-in functionality for it.

The BACK button (case 166) is not handled by calling any function. Media Center already handles user input from the BACK button by navigating to the previous page, whether it is an HTML page or some other page in Media Center. In your HTML application, you can provide additional functionality to the BACK button by adding a function call to this case, and you can prevent Media Center from navigating back by returning true. (However, this behavior may be contrary to your user's expectations.)

HTML pages receive the onload event when they initially load, and when the user presses the BACK button to navigate between HTML pages in the same application. The page will also receive the onload event when the user presses the BACK button to return to the application from a Media Center view such as full screen. When this happens, the page is not actually reloading, so global variables retain the same values they had when the user left. This can cause problems in any logic attached to the onload event that assumes that the global variables are getting reset to their original values whenever the event occurs. A simple way to avoid such problems is to instruct Media Center not to fire this event, by setting the EnableOnLoadOnReturnFromMediaCenter property to false when the page loads.

HTML applications often must preserve the state of an HTML page when the user navigates away from the page, to ensure that the state can be restored when the user returns to the page even if the page has been reloaded in the process. For example, suppose the user presses the Media Center (green) button on the remote control while playing a game application, causing Media Center to navigate away from the game. When the user presses the BACK button, they expect to return to the game and find it in the same state as before the navigation occurred.

Media Center raises the onunload event immediately the user navigates away from an HTML page, and raises the onload event when the user returns. By including handlers for these events, an HTML application can save the state of an HTML page when the user navigates away, and restore the state when the user returns.

See Also

Previous Next

© 2005 Microsoft Corporation. All rights reserved.