Cool, since you're good with the APIs, it should be easy for you. I'm going to post an example, though, just in case someone else has this question and finds this discussion searching the forums.
The basic idea is to define a javascript function that will be called when a key is pushed down on the button. The onkeydown event is run when that happens... it will need to check for key code 13, which is enter.
You can define this function anywhere. One easy thing to do is to define it in the "onload" event for your screen. Provided that you attach it to the browser's "window" object, it will be global, so once the screen loads, you'll be able to call it from anywhere.
onload event:
Code: Select all
window.keyDownHandler = function(event, element) {
event = event || window.event;
var key = event.keyCode || event.which;
if (key == 13) {
pui.click(element);
preventEvent(event);
}
}
The first two lines are for compatibility with old versions of Internet Explorer. Old versions of IE do not pass an event object, but instead use a global variable (i.e. a variable attached to the window object) named event. And the event didn't contain a "keyCode" element, but instead had an element called "which" that did the same thing. In this respect, these old versions of IE didn't follow web standards. Newer versions of IE fixed this, and of course all versions of Firefox, Chrome, Opera, Safari, etc all used the standards.
So after the first two lines, "event" will be the event (whether old IE or not...) and "key" will be the keycode (whether old IE or not.)
Then the task is easy... if the key is 13 (enter) use the pui.click() API to click the element... which will be the graphic button or whatever it is that has this assigned to its onkeydown. preventEvent() prevents the enter key from being propagated up -- so if there's other things (such as a screen-wide keyboard handler) the enter key will not be sent to it.
Now assign this function (without parenthesis) to the onkeydown property of the graphic button, or any other element on the screen (I tested it with gradient buttons, css buttons, regular buttons and of course, graphic buttons). So the property looks like this:
onkeydown event:
It's important to exclude parenthesis here, because that allows the browser to pass the event and element parameters to the function.
For some widget types (including gradient buttons, css buttons, images, etc) you will need to set the "tab index" property to a positive number in order for the tab key to stop at the element. That is what the tab index property does -- when it is positive, the tab key will tab to it, when it is negative, it won't.
That should be it... now either the "response" or "onclick" event for the button will fire when you press enter while focusing on the button.
Hope that is helpful to someone :-)