API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Capturing Keystrokes
In the R5 designer client, each form has many LotusScript and JavaScript events which you can put code into. One of the JavaScript events is called onKeyDown. This event is triggered every time a key is pressed on the keyboard. Using this knowledge, you could create your own key capturing event.

Why would you want to?

Well, there's a few reasons we can think of. First, you may want to capture the ESC key and trigger a JavaScript history.back() function so the ESC key on the browser will mimic the ESC key in the Notes client.

Another reason would be to prevent certain things from happening. For example, you may not want the user to reload the current page, so you can capture the F5 key and send a return false message back to the browser which will prevent the key from being executed. The same thing can be thought of for the CTRL key and the ALT key on a form where only text will be entered.

To capture keystrokes, it's a little different in IE and Netscape (of course). Here is code which will work in either browser:

function getKey(keyStroke) {
   var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
   var keyString = String.fromCharCode(keyCode).toLowerCase();
}

Your form's onKeyDown event should then simply call getKey() to enter the function.

Some values for keyCode (tested on a Windows OS, you'll have to check for Macs and other operating systems):
CTRL - 17ALT - 18SHIFT - 16ESC - 27BACKSPACE - 8
END - 35DELETE - 46HOME - 36PAGE UP - 33PAGE DOWN - 34
INSERT - 45F1 - 112Fn - 111+n (ex: F11 = 122)Windows Key (CTRL+ESC) - 92 

There's also an alternative method - one that isn't specific to the Domino Designer, and could therefore be used in a regular HTML page or in release 4 of Domino. Put the following script into your JSHeader:

if (document.layers) { document.captureEvents(Event.KEYPRESS); }
document.onkeypress = getKey;
function getKey(keyStroke) {
   var keyCode = (document.layers) ? keyStroke.which : event.keyCode;
   var keyString = String.fromCharCode(keyCode).toLowerCase();
}