Table of contents
  1. Keyboard Event / keydown / keyup / keypress
    1. Read Barcode Scanner Input Event
      1. React Typescript Example




Keyboard Event / keydown / keyup / keypress

Read Barcode Scanner Input Event

const CheckInPCF = {};

function Scan(evt: Event): void {
    const e: KeyboardEvent = evt as KeyboardEvent;
    const timeDiff = e.timeStamp - CheckInPCF.LastTimeStamp;
    CheckInPCF.LastTimeStamp = e.timeStamp; //"global"

    //console.log(e.key + ': ' + timeDiff);

    if (timeDiff < 100) {
        if (e.key == "Enter") {
            //Assemble complete scan text
            CheckInPCF.ScanText =
                CheckInPCF.FirstCharacterCandidate + CheckInPCF.ScanText; //.replace('\u000D','');

            //console.log('finished: ' + CheckInPCF.ScanText);
            CheckInPCF._this._notifyOutputChanged(); //Power Apps related
        } else {
            CheckInPCF.ScanText += e.key;
        }
    } else {
        CheckInPCF.ScanText = "";
        CheckInPCF.FirstCharacterCandidate = e.key;
    }
}

React Typescript Example