Monday, February 5, 2007

Input Handling

Welcome back for another blog entry.

Today we have a quick tip on input handling (and playing with .NET variables) in your MCML interfaces.

Every object in your MCML interface has an Input object associated with it. This is what allows you to find out if the item has mouse or keyboard focus. It ALSO lets you control how that focus works.

To tell if the mouse is hovering over an object, you need to check the [Input.MouseFocus] property. Since every object has it's own 'Input' object, the properties of Input will always refer to this object only (or it's children, if you are using DeepFocus).

<UI Name = "Selectable">
  <Rules>
    <Condition Target="[Input.MouseFocus] Value="true"\>
      <Actions>
        <Set Target=[TextObject.Color]" Value="Red"\>
      </Actions>
    </Condition>
  <\Rules>
  <Content>
    <Text Content="Push Me" Color="White" Name="TextObject"\>
  <\Content>
<\UI>

The trick to using their advanced properties is simple, but can throw you if you are new to MCML. Objects like Input are NOT actually XML tags, despite the fact that in the documentation they are shown as XML. Instead, they are .NET objects, and you set the properties of the Input object through the Default tag of your Rules object.

For example, we can mark a panel as being able to receive focus with the KeyInteractive property.

<UI Name = "Selectable>
  <Rules>
    <Default Target="[Input. KeyInteractive] Value="true"\>
  <\Rules>
  <Content>
    <Text Content="Push Me"\>
  <\Content>
<\UI>

This creates a text object that you can navigate to with you remote/keyboard.

One more hint - MCML's default is that a mouse-focus event always fired off a matching key-focus event. Sometimes, this just isn't right.

For example, in the AreaBar (the pivot bar, or the blue list of sorting options that appears in most genuine Media Center screens), you find that when you navigate by key-press or remote, you automatically select the next area/option that you navigate to.

When using a MOUSE, you only HIGHLIGHT it. You have to click the mouse button to select the option.

However, the default behaviour for Media Center is to automatically set 'KeyFocus' to true every time 'MouseFocus' is. This sort of thing is great for regular buttons, but isn't effective for this particular control.

So to emulate this behavior, you need to use

<Rules>
  <Default Target="[Input. KeyFocusOnMouseEnter] Value="false"\>
<\Rules>

This prevents [Input.KeyFocus] from being true every time that [Input.MouseFocus] is.

No comments: