KeyCode Test
This is meant as a simple way to test the keyCode values produced on various devices. Since this is a publicly available site, you can easily send the link to customers for them to try it, and you can easily open it from your mobile devices (even if using a cell phone network.)
The output below the text boxes shows the keyCode and whether the shift key was pressed. So 107 false
indicates that it was keyCode 107, and the shift key was not pressed. Whereas 187 true
indicates that keyCode 187 was pressed, and the shift key was pressed.
Also the screen-level onkeydown event is set to the following:
if ( (pui.touchDevice && event.keyCode==187 && event.shiftKey==true)
||(!pui.touchDevice && event.keyCode==107)) {
event.preventDefault();
}
Since touch-based devices (such as smart phones) do not usually have numeric keypads, we look for keyCode 187 (the = key) and Shift being pressed at the same time.
This is because on most keyboards, the + symbol shows up above the equal sign, so shift =
is the same as pressing +
. On non-touch devices (such as a PC keyboard) we use keyCode 107, which is the +
key on the numeric keypad.
When the appropriate key is pressed, we use event.preventDefault()
to
block the brower's default event -- which would be putting the +
symbol into the field. This cannot be done in the subsequent onkeyup
event because onkeyup
fires after the character has already been placed in the field.
Then, in the screen-level onkeyup event, we do this:
if ( (pui.touchDevice && event.keyCode==187 && event.shiftKey==true)
||(!pui.touchDevice && event.keyCode==107)) {
pui.fieldExit(false);
event.stopPropagation();
event.stopImmediatePropagation();
}
Here, we're checking for the same keys, but now we're calling pui.fieldExit function to make it act like the 5250 field exit key was pressed. Next, we call event.stopPropagation()
and event.stopImmediatePropagation()
to prevent other code (such as the pui["auto tab"]
feature) from also acting on this keypress. It is important that the propagation is stopped via the onkeyup
event because the pui["auto tab"]
feature runs in the onkeyup event. If we tried to block propagation on the onkeydown
the auto tab could also fire, causing it to tab twice.
Comments
Bill
3 years ago
Does not work if the auto tab occurs first. For example, if the scanner sends '+' suffix and the scanned data = the max length of the field, the auto tab move you to the next field before the key down picks up the '+'. You have to completely ignore the '+' (no field exit) if the focus has changed to a new field. This works fine if the scanned data < max length.