Example of Ctrl-Enter key event handling in JavaScript

The following sample demonstrates the handling of Ctrl-Enter event in Javascript. You might wish to embed the code like this in Greasemonkey script with some modifications due to limitations in sandbox environment1). The example of Greasemonkey script for http://babelfish.yahoo.com online translator can be found here.

<html>
<head>
    <title>Ctrl-Enter test</title>
</head>
<body>
 
<form name="test">
<textarea name="message" rows="6" cols="40" wrap="virtual"></textarea>
 
<script type="text/javascript">
    function ctrlenter(k)
    {
        if (k)
        {
            ctrl = k.ctrlKey;
            k = k.which;
        }
        else
        {
            k = event.keyCode;
            ctrl = event.ctrlKey;
        }
 
        if ((k==13 && ctrl) || (k==10))
        {
            alert('Ctrl-Enter was pressed');
            //this.form.submit();
            return false; // consume the event
        }
 
        return true;
    }
 
    document.forms.test.message.onkeydown = ctrlenter;
</script>
 
</form>
 
</body>
</html>