FAQ - This post is taken from a list of the most frequently asked questions during the pre-release of the WDK
I have been trying to get the key handler working from a button with the following code. It never gets called from what I can tell. If I highlight the button I can hit many keys including right/left and numbers and see the doggy.wakeup outputs from the system so I know the keys are going somewhere but my logging does not get called. The onSelect here does work. Can you tell me what I am doing wrong? How would you capture a key that is not the select button?
var menuItem = new KONtx.control.TextButton(
{
id: 'menuItem-' + buttonIndex,
label: button.Title.Text,
events:
{
onKeyDown: function()
{
log('============keycode ='+event.keyCode);
},
onSelect: function()
{
log('============keyselect');
},
},
styles:
{
vOffset: vertical_offset,
height: $showtime.styles.menu.button_grid_row.height,
},
textStyles: $showtime.styles.menu.button_name
});
We should not use onKeyDown events. As far as capturing other keys, the only key you have outside of the standard navigation keys (up/down/left/right/OK) is the Back/Return key. We will be expanding the keyhandler at some point, but you should design around this feature in the first phase of the widget. Please let me know the interaction you are trying to accomplish and we can try to help out.
I don’t think you should use the onKeyDown event when you are using the KONtx framework, onSelect should work:
var section0 = new KONtx.control.TextButton({
label: $_('section_0'),
secure: false,
styles: {
height: buttonHeight
},
textStyles: buttonTextStyles,
events: {
onSelect: function(type, args, obj) {
KONtx.application.history.changeState({
callback: function() {
KONtx.application.getCurrentApp().switchSection('section-0');
}
})
}
}
}).appendTo(menuContainer);