Sample Script Key Handler

I've been handling all key/remote commands from the Markup. I now have a scenario where I need to capture some key events in the script.

Can someone post or point me to a simple key handler I could not find a clear description in the spec.

Thanks.



Answer this question

Sample Script Key Handler

  • Abbbbbs

    Spec reference will do too. Thanks.


  • Hemant Hindlekar

    Thanks Bryan!


  • sigol

    function doKeyEventUp(evt)
    {

    switch (evt.key)
    {
    case 0xFA:
    // Do stuff for VK_PLAY
    break;
    case 0xB3:
    // Do stuff for VK_PAUSE
    break;
    }
    evt.stopPropagation();
    evt.preventDefault();
    }

    addEventListener("controller_key_up", doKeyEventUp, false);

    This is pretty simplified. I'd normally have a set of variables VK_PLAY etc assigned to the key values for readability. You can find the values in Annex V. You can also experiment with controller_key_up and controller_key_down, I can't remember offhand which is better for catching all keys.

    The stopPropagation() and preventDefault() stops the key from moving on through the system and alllows you to override default behaviours.

    There's a section on Controller Key Events in Annex Z.5.3, and generic events in Z.6


  • Sample Script Key Handler