Keyboard Mapping - Part 2
In Part 1 we described how to map every key to custom character. This time we will describe how to map terminal commands as Field+, Field-, FieldExit etc. to different keys.
Command mapping is similar to key mapping. Instead we will map registered events for special terminal commands.
For example, Field+ and Field- by default are mapped to numeric pad + and - keys. In this scenario it is impossible to type + or - character from numeric pad.
To change that, we need to create custom mapping which will replace existing one. One of our clients wanted to remap NUM- from Field- to minus (-) character.
Here is how we did it...
NOTE: At the bottom one can find default functions mapping
Custom mapping steps
- go to [users]\io.greenscreens\etl\data
- create txt file name kmap.json.
- paste default mapping from bottom of this post into created file
- find and remove following mapping
{mm: '@A@-', which: 109, altKey:false, name:'FMINUS'}
- save file
- go to web admin console
- open Customization (left side bar) and select Footer
- Paste following code (don't forget to press save icon)
<script>
$(window).on('greenscreens', function(){
Tn5250.KeyMap.install('kmap.json');
});
</script>
- Open web terminal and try Num-, now it should be minus (-) char instead Field-
Key definition options
Every key has JSON object definition for event mapping. Below is a sample with all available properties.
NOTE: Not all property combinations are valid.
{
mm: '@@',
which: 64,
aid: 248,
forced:true,
altKey:true,
ctrlKey:true,
shiftKey:true,
type:'keypress',
name:'AT',
type:'keypress',
mode : 1,
originalEvent: {location: 0}
},
- aid - 5250 terminal code for remote function key as PFnn, Enter, SystemReq, Reset etc...
- altKey - should ALT be pressed
- ctrlKey - should CTRL be pressed
- forced - will ignore key buffering (buffer is cleared)
- mm - HLL api specification command
- mode - keyboard operation mode (can have 2 modes)
- name - event name registered in application
- originalEvent: {location: 0} - to recognize key physical location as left or right side of the keyboard (for keys as ALT, CTRL ENTER )
- shiftKey - should SHIFT be pressed
- type - type of event to catch : 'keypress', 'keyup', 'keydown'
- which - JavaScript key code to match
Default mapping structure
[
{mm: '@1', which: 112, aid: 49, name:'PF1'},
{mm: '@2', which: 113, aid: 50, name:'PF2'},
{mm: '@3', which: 114, aid: 51, name:'PF3'},
{mm: '@4', which: 115, aid: 52, name:'PF4'},
{mm: '@5', which: 116, aid: 53, name:'PF5'},
{mm: '@6', which: 117, aid: 54, name:'PF6'},
{mm: '@7', which: 118, aid: 55, name:'PF7'},
{mm: '@8', which: 119, aid: 56, name:'PF8'},
{mm: '@9', which: 120, aid: 57, name:'PF9'},
{mm: '@a', which: 121, aid: 58, name:'PF10'},
{mm: '@b', which: 122, aid: 59, name:'PF11'},
{mm: '@c', which: 123, aid: 60, name:'PF12'},
{mm: '@d', which: 112, shiftKey: true, aid: 177, name:'PF13'},
{mm: '@e', which: 113, shiftKey: true, aid: 178, name:'PF14'},
{mm: '@f', which: 114, shiftKey: true, aid: 179, name:'PF15'},
{mm: '@g', which: 115, shiftKey: true, aid: 180, name:'PF16'},
{mm: '@h', which: 116, shiftKey: true, aid: 181, name:'PF17'},
{mm: '@i', which: 117, shiftKey: true, aid: 182, name:'PF18'},
{mm: '@j', which: 118, shiftKey: true, aid: 183, name:'PF19'},
{mm: '@k', which: 119, shiftKey: true, aid: 184, name:'PF20'},
{mm: '@l', which: 120, shiftKey: true, aid: 185, name:'PF21'},
{mm: '@m', which: 121, shiftKey: true, aid: 186, name:'PF22'},
{mm: '@n', which: 122, shiftKey: true, aid: 187, name:'PF23'},
{mm: '@o', which: 123, shiftKey: true, aid: 188, name:'PF24'},
{mm: '@C', which: 19, aid: 189, name:'CLEAR'},
{mm: '@S@E', which: 19, shiftKey: true, aid: 246, name:'PRINT'},
{mm: '@A@C', which: 19, shiftKey: false, altKey: true, aid: 240, name:'TEST'},
{mm: '@H', which: 112, altKey: true, aid: 243, name:'HELP'},
{mm: '', which: 36, altKey: true, aid: 248, name:'HOME'},
{mm: '@u', which: 33, aid: 244, name:'PGUP'},
{mm: '@v', which: 34, aid: 245, name:'PGDOWN'},
{mm: '@A@H', forced:true, which: 27, shiftKey: true, aid: 1031, name:'SYSR'},
{mm: '@A@Q', forced:true, which: 27, aid: 1037, name:'ATT'},
{mm: '@R', forced:true, type: 'keyup', shiftKey: false, ctrlKey: false, altKey: false, which: 17, originalEvent: {location: 1}, aid: 1032, name:'RESET'},
{mm: '@C', type: 'keyup', shiftKey: true, ctrlKey: false, altKey: false, which: 17, originalEvent: {location: 1}, aid: 189, name:'CLEAR'},
{mm: '@N', which: 13, shiftKey: true, originalEvent: {location: 0}, name:'NEWLINE'},
{mm: '@N', which: 13, shiftKey: true, originalEvent: {location: 3}, name:'NEWLINE'},
{mm: '@N', which: 17, ctrlKey : true, shiftKey: true, originalEvent: {location: 2}, name:'NEWLINE'},
{mm: '@E', which: 13, aid: 241, originalEvent: {location: 3}, name:'ENTER'},
{mm: '@E', which: 13, aid: 241, originalEvent: {location: 0}, mode : 2, name:'ENTER'},
{mm: '@E', which: 17, ctrlKey : true, aid: 241, originalEvent: {location: 2}, mode : 1, name:'ENTER'},
{mm: '@A@E', ctrlKey : true, which: 17, originalEvent: {location: 2}, mode : 2, name:'FEX'},
{mm: '@A@E', which: 13, originalEvent: {location: 0}, mode : 1, name :'FEX'},
{mm: '', ctrlKey : true, altKey : true, which: 17, originalEvent: {location: 2}, mode : 2, name:'FEXB'},
{mm: '', altKey : true, which: 13, originalEvent: {location: 0}, mode : 1, name :'FEXB'},
{mm: '@U', which: 38, name:'UP'},
{mm: '@V', which: 40, name:'DOWN'},
{mm: '@L', which: 37, name:'LEFT'},
{mm: '@Z', which: 39, name:'RIGHT'},
{mm: '@0', which: 36, name:'FIELDSTART'},
{mm: '@q', which: 35, name:'FIELDEND'},
{mm: '@F', which: 35, shiftKey: true, name:'ERASEEOF'},
{mm: '@A@F', which: 35, altKey: true, name:'ERASEINPUT'},
{mm: '@A@9', which: 111, altKey: true, name:'MIRROR'},
{mm: '@A@9', which: 111, ctrlKey: true, name:'MIRROR'},
{mm: '@A@9', which: 55, altKey: true, shiftKey:true, name:'MIRROR'},
{mm: '@@', which: 64, altKey:true, ctrlKey:true, type:'keypress', name:'AT'},
{mm: '@O', which: 32, type:'keypress', name:'SPACE'},
// num keys without alt
{mm: '@A@+', which: 107, altKey:false, name:'FPLUS'},
// remove this to enable char minus instead Field-
{mm: '@A@-', which: 109, altKey:false, name:'FMINUS'},
// num keys with alt
{mm: '@A@+', which: 107, altKey:true, name:'FPLUS'},
{mm: '@A@-', which: 109, altKey:true, name:'FMINUS'},
// normal keyboard segment
{mm: '@A@+', altKey: true, which: 187, name:'FPLUS'},
{mm: '@A@-', altKey: true, which: 189, name:'FMINUS'},
{mm: '@T', which: 9, name:'TABNEXT'},
{mm: '@B', shiftKey: true, which: 9, name:'TABPREV'},
{mm: '', which: 111, shiftKey: true, name:'RTLMERGE'},
{mm: '', which: 111, name:'RTL'},
{mm: '', altKey: true, which: 73, name:'RTLBOX'},
{mm: '@Ar', which: 82, shiftKey:false, altKey:true, name:'RTL'},
{mm: '', which: 55, shiftKey:true, altKey:true, name:'RTL'},
{mm: '', which: 86, altKey:true, name:'RESIZE'},
{mm: '', which: 45, altKey:true, name: 'DUP'},
{mm: '@A@I', which: 45, name: 'OWR'},
{mm: '@D', which: 46, name:'DEL'},
{mm: '@<', which: 8, name:'BACKSP'},
{mm: '', type: 'keyup', which: 44, name:'PrintScr'},
{mm: '@s', which: 145, name:'ScrollLock'},
{mm: '@t', which: 144, name:'NumLock'},
{mm: '@Y', which: 20, name:'CapsLock'},
{mm: '', altKey: true, shiftKey: true, which: 187, name:'CROSSHAIR'},
{mm: '', type: 'keyup', ctrlKey: true, which: 114, name:'NOP'},
{mm: '@rr', ctrlKey: true, shiftKey:false, which: 82, name:'REFRESH'},
{mm: '', altKey: true, which: 37, name:'NOP'},
{mm: '', altKey: true, which: 39, name:'NOP'},
{mm: '', type: 'keyup', ctrlKey: true, altKey: true, which: 17, originalEvent: {location: 0}, name:'NOP'},
{mm: '', altKey: true, shiftKey: true, which: 70, name:'TOGGLEFONT'},
{mm: '', altKey: true, shiftKey: true, which: 84, name:'TOGGLETHEME'},
{mm: '@Am', altKey: true, which: 77, name:'MARKSTART'},
{mm: '', altKey: true, shiftKey: true, which: 77, name:'MARKEND'},
{mm: '', ctrlKey: true, shiftKey: true, which: 65, name:'SELECTFIELD'},
{mm: '@ra', type: 'keyup', ctrlKey: true, which: 65, name:'SELECTALL'},
{mm: '@rc', type: 'keyup', ctrlKey: true, which: 67, name:'COPY'},
{mm: '', shiftKey: true, which: 32, name:'INSERTSPACE'},
{mm: '', altKey: true, which: 38, name:'PASTEMODENEXT'},
{mm: '', altKey: true, which: 40, name:'PASTEMODEPREV'},
{mm: '', altKey: true, shiftKey: true, which: 76, name:'TOGGLELOGGING'},
{mm: '@Au', altKey: true, which: 85, name:'TOGGLEUI'},
{mm: '@Ak', altKey: true, which: 75, name:'TOGGLEKEYBAR'},
{mm: '@Ab', altKey: true, which: 66, name:'TOGGLEBRAILLE'},
{mm: '@Aa', altKey: true, which: 65, name:'TOGGLEATTR'},
{mm: '@Ax', altKey: true, which: 88, name:'TOGGLESISO'},
{mm: '', altKey: true, shiftKey: false, which: 70, name:'MACROFIELDS'}
]