JavaScript keyboard mapping

Mainframe screens can contain fixed and variable fields (forms). G&R web-based emulators represent these by HTML 'forms'. HTML forms are rather different from mainframe forms, and the browser lacks many features of a terminal when entering data into the fields of a form. Typical mainframe field attributes might be numeric, must fill or must enter. Typical terminal keyboard functionality might be autoskip to the next variable field when the current field is full. To give functionality similar to a terminal, we supply two JavaScripts, gweb.js and gwebkbd.js. These are engaged by the Gweb header file, and require that the user's browser is able to map keyboard events to JavaScript events. Not all browsers are able to do this.

Mapping of the keyboard using JavaScript to process keyboard events works depending on the application version of your browser. This is not the same as the version of the browser. For example, Microsoft Internet Explorer version 6.0 still uses application version 4.0. Netscape 6.2 still uses application version 5.0. MSIE application version 4.0 and NS application version 5.0 both have JavaScript implementations that support keyboard mapping. Earlier application versions, and some other browsers may give limited functionality, but are not recommended or supported as regards their JavaScript capability.

Testing the key bindings

To give keyboard functionality similar to that of a terminal, two JavaScripts are provided in the script directory.

gwebkbd.js
This script is a table that maps keypress combinations to keyboard functions.
gweb.js
This script contains event handlers for keyboard events. They are engaged by the tags added by Gweb to the HTML pages it generates to simulate the terminal screen e.g. onKeyDown="return doKeyDown(event);". The script looks up the keypresses in the gwebkbd.js table to find the appropriate action.

You can test your browser's keyboard events while reading this page. For example, the default table in gwebkbd.js expects the 'Home' key to return a keycode value of 36, and the table binds this value to the gweb.js JavaScript function 'CursorHome'. Assuming your browser supports keyboard mapping, if the 'Home' key on your keyboard does not work when using Gweb, it is because your keyboard is returning another value. If you press the 'Home' key now, a JavaScript message box will appear that tells you what your keyboard returned, and to which Gweb JavaScript function it is currently mapped. Try it now!!

You can use this functionality to gain the information you need in order to customize the default keyboard mapping table gwebkbd.js.

If you want the 'Home' function to be on a completely different key, you can press the key, or key combination (Shift, Alt, Ctrl) that you would like to use, to see what value is returned. Note it, and then modify the gwebkbd.js table to move the 'CursorHome' function to the desired key or key combination (don't forget Shift/Alt/Ctrl). In this way you can bind any key or key combination to any function provided by the JavaScripts.

Customization

We recommend you limit your customization of Gweb JavaScript to editing gwebkbd.js. With very little effort and virtually no knowledge of JavaScript you can re-map your keyboard by editing this file. The default bindings are given in the table below. In gwebkbd.js you will find a JavaScript array of hashes called, "fKeyMaps". A typical element of this array is:

{ keyCode:57, isMapped:true, shift:false, ctrl:false, alt:true, vKey:"cmd:f9" }, // Alt/9

"keyCode"
Keycodes are delivered to JavaScripts as Unicode, but the table uses the decimal representation. Here keyCode 57 is the decimal representation of the Unicode key code 0039 which is the character "9". For those who are familiar with the UTF scheme, 0039 is found in UTF-8.
"isMapped"
A Boolean value indicating whether this particular key is bound or not. Here, it is bound.
"shift"
A Boolean value indicating the status of the shift modifier. Here no shift modifier is applied.
"ctrl"
A Boolean value indicating the status of the control modifier. Here no control modifier is applied.
"alt"
A Boolean value indicating the status of the alt modifier. Here the alt modifier is applied.
"vKey"
A string value denoting the Gweb JavaScript function bound to this keycode. The functions can be local (Home, Cursor up, tab) or map to Gweb command functions. Here, the key is mapped to the Gweb F9 function.

Gweb JavaScript functions that map to Gweb functions are preceeded with a "cmd:" prefix. Key bindings without this prefix are the names of local keyboard functions coded in gweb.js.

Each element of the array is placed on a separate line which ends with a comment string. Here, " // Alt/9" is a comment that the key combination Alt/9 is mapped to the Gweb F9 function.

The order and number of elements in fKeyMaps are not important.