views:

185

answers:

1

Using Mootools, but a generic answer is fine.

I would like to remap the 'Enter' key in a web application.
When they hit 'Enter' it should react as though the 'Shift-Enter' has been pressed.

I would just stop the enter event, and use exec.insertHTMLor its ilk, but FF's implementation is buggy on many elements.

I imagine that I could fire a key event, same as I could fire a click or other event:

click: $('myElement').fireEvent('click', arg1);

keyevent: $('myElement').fireEvent('keydown' ???);

But I cant figure out how.

A: 

I don't know exactly what you're looking for, but the following fires the 'shiftenter' event when the enter-key is pressed. Notice that you have to specify the 'shiftenter' event yourself.

$('element').addEvent('keydown', function(e) {
    new Event(e).stop();

    if (e.key == 'enter') {
        this.fireEvent('shiftenter');
    }
});
Björn
Thanks. But I know how to get it to fire my own custom event. I wanted it to react as though the shift+enter keys on the keyboard were pressed.
SamGoody