shortcut question

Hello,

I have a special question using functional keys for shortcuts.

Normally a shortcut is setted like this:


Button btn = new Button(“Alt+A”);
ShortcutAction action = new ShortcutAction(“Alt+A”, ShortcutAction.KeyCode.A, new int[]{ShortcutAction.ModifierKey.ALT});
btn.setClickShortcut(action.getKeyCode(), action.getModifiers());

For the normal keys from A to Z and in combination with ALT it works fine.

But when I try this…


Button btn = new Button(“F8”);
ShortcutAction action = new ShortcutAction(“F8”, ShortcutAction.KeyCode.F8, null);
btn.setClickShortcut(action.getKeyCode(), action.getModifiers());

…it doesn’t work, because the vaadin application runs on a browser and the
functional keys are initialize with default values (e.g. F5 = refresh).

How can I override the functional keys from F1 to F12?

Thanks for your help,
steff

The allowed key bindings vary greatly between browsers.

See the following article, which I think was written by Marc:

[list]

[]

Keybindings in Web Browsers

[
]

Detailed keybinding tables

[/list]For example, in Firefox, you can bind any function keys, but in IE and especially in Opera you run into troubles.

Hello Marko,

thanks for your answer and the two links!

I think I have to explain my problem a bit more.
The HTML Sollution to disable Functional Keys does function well. (Inside an HTML page)

BUT when I try to set the functionality with Vaadin it doesn’t work well.
I use a handler to generate a string from a file which includes the JavaScript.
And this generated String I set with

application.getCurrentApplication().getMainWindow().executeJavaScript(generatedString);

When I add an alert to the script I see that it is loaded.

And now the problem. I have two ShortcutActions on two Buttons.
The First Button reacts on “ALT+A” and the second Button on “F6”. I use this,
because in the second link from you there is mentioned that this one should function.

The Actions behind the two Buttons are only syso in the command line. Both prints only
the name of the pressed Button.

Now when I start the project. I can use ALT+A to see “Button 1”. But there is no reaction on F6.

My actual JavaScript looks like that:

var element = document;
if (element.addEventListener) {
 	element.addEventListener('keydown', listener, false);
        element.addEventListener('keyup', cancelEvent, false);
        element.addEventListener('keypress', cancelEvent, false);
} else if (element.attachEvent) {
        element.attachEvent('onkeydown', listener);
 	element.attachEvent('onkeyup', cancelEvent);
       element.attachEvent('onkeypress', cancelEvent);
}


function listener(e) {
	e = e || window.event;
        var code;
        if (e.keyCode) {
         code = e.keyCode;
 } else if (e.which) {
 	code = e.which;
 }

 return cancelEvent(e);
}

function cancelEvent(e) {
        
        e = e || window.event;
        e.cancelBubble = true;
        e.returnValue = false;
        if (e.stopPropagation) e.stopPropagation();
        if (e.preventDefault) e.preventDefault(); 
	return false;
}

Thanks for the help again,
Stefanie