0

Widgets Keyboard shortcusts - should of posted here

Hello I am a widget newbie and wish to ask the following question

Can anyone give me a javascript code example of how to respond to a keyboard press in the widgets environment.

For example in my view I have 5 items and instead of selecting them I wish to use keyboard strokes (1,2,3,4,5) in order to navigate to the next view.

I have been trying to look through the Yahoo Developer Guide for any examples but no luck so far.

Any help would be appreciated

Thanks

by
2 Replies
  • Hi there,

    I am a newbie as well. You might want to take a look at KONtx.utility.KeyHandler.map in the documentation at http://developer.yahoo.com/connectedtv/kon...idget_KONtx.pdf. Looks like you can have keydown events and you can recognize which keys are pressed based on the keyCode. I guess it should be possible via the application event handler for the event onWidgetKeyPress.

    Thanks,
    Vivek
    0
  • QUOTE (jani.vivek @ Oct 1 2010, 05:41 PM) <{POST_SNAPBACK}>
    Hi there,

    I am a newbie as well. You might want to take a look at KONtx.utility.KeyHandler.map in the documentation at http://developer.yahoo.com/connectedtv/kon...idget_KONtx.pdf. Looks like you can have keydown events and you can recognize which keys are pressed based on the keyCode. I guess it should be possible via the application event handler for the event onWidgetKeyPress.

    Thanks,
    Vivek

    The KONtx.utility.KeyHandler.map object maps to the value in the keyCode property of the event payload. It's a convenience so you as the developer don't have to worry about remembering what the actual number is. Of course, you don't have to use it.

    Here's one way to capture keystrokes.

    Subscribe to the application class in update view:
    CODE
    	updateView: function() {
    this._handleKeyPress.subscribeTo(KONtx.application, 'onWidgetKeyPress', this);
    },


    Define the view method that is listening for the onWidgetKeyPress event:
    CODE
    	_handleKeyPress: function(event){

    //NOTE if you're unsure of the value of keyCode you can log it to find out;
    log("________________________________________________________________");
    log("________________________________________________________________");
    log(event.payload.keyCode);
    log("________________________________________________________________");
    log("________________________________________________________________");

    switch(event.payload.keyCode) {
    case 19:
    //do something here;
    break;
    case 415:
    //do something here;
    break;
    case KONtx.utility.KeyHandler.map.F10:
    KONtx.HostEventManager.send("exitToDock");
    break;
    }
    }


    This should get you started. There's more to do, of course. For example, you should always unregister the listener when the view exits.

    - Ben
    0

Recent Posts

in Design / Interaction - Yahoo! TV Widgets