About This Space

Test KeyCodes and pui.fieldExit() routine.


Last updated on October 19, 2021

Public Permissions:   View   Open/Fork   Run   Comment  

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

Write Preview Markdown: bold italic code link
Post

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.

Filters:

Popular Recent

Simple REST API to test HTTPAPI Application for Christ Larsen https://www.scottklement.com/forums/viewtopic.php?t=71

3348

0

0

This interactive app prompts the user for key fields to lookup a database record and displays the results

5593

0

0

Scott's family wants to keep track of restaurants and what we liked about them.

5376

0

0

Based on the one Alex created for the California office, but added links to restaurant menus and the ability to rate the experience. (Removed "delete" option so ratings/menus will always be there.)

5729

1

1

This app consumes a web service and display the information in a grid

5520

0

0

example mortgage application

4845

0

0

Eat other NodeRun players to win prizers

5614

0

Really, its just the fibers template

3458

0

A demo of how to build Rich Displays in the Visual Designer that integrate with external CSS and JavaScript file

5535

0

0

Scott Klement's Meeting Timer

3681

0

0

Example of modifying allowed upload types with JavaScript at run-time

5298

0

0