Barcode Scanning/Debug

From PartKeepr Wiki
Revision as of 12:12, 15 June 2017 by Felicitus (talk | contribs) (Created page with "If barcode scanning does not work properly, you can copy and paste the following code into your browser's JavaScript console. This overrides the default barcode scanning class...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

If barcode scanning does not work properly, you can copy and paste the following code into your browser's JavaScript console. This overrides the default barcode scanning class, printing debug output on the console.

PartKeepr.getApplication().barcodeScannerManager.onKeyPress = function (e)
    {
        var hotKeyPressed = false;

        var hotKey = PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.key", "");

        if (hotKey === "") {
            console.log("No hotkey configured, returning");
            return;
        }

        console.log("got key event:");
        console.log(e);
        if (e.event.key === hotKey) {
            hotKeyPressed = true;
            console.log("Hotkey not pressed");

        }

        if (PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.modifierCtrl", false)) {
            if (!e.ctrlKey) {
                console.log("ctrl hotkey modifier not pressed");
                hotKeyPressed = false;
            }
        }

        if (PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.modifierShift", false)) {
            if (!e.shiftKey) {
                console.log("shift hotkey modifier not pressed");
                hotKeyPressed = false;
            }
        }

        if (PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.modifierAlt", false)) {
            if (!e.altKey) {
                console.log("alt hotkey modifier not pressed");
                hotKeyPressed = false;
            }
        }

        if (hotKeyPressed) {
            console.log("starting key monitoring");
            this.startKeyMonitoring();
            return;
        }


        if (this.monitor) {
            if (PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.enter", true)) {
                if (e.event.code == "Enter") {
                    this.stopKeyMonitoring();
                    return;
                }
            }

            if (!e.isSpecialKey()) {
                this.monitoredKeys += e.event.key;
            }
            this.runnerTask.delay(
                PartKeepr.getApplication().getSystemPreference("partkeepr.barcodeScanner.timeout", 500));
            e.stopEvent();
        }
    };
    
    Ext.get(document).on("keydown", PartKeepr.getApplication().barcodeScannerManager.onKeyPress, PartKeepr.getApplication().barcodeScannerManager, {
            priority: 10000
        });