@kduma-autoid/capacitor-sunmi-keyboard-handler

Handler for processing input from Sunmi hardware barcode scanners (builtin and external) and external Sunmi programmable keyboard.

Install

npm install @kduma-autoid/capacitor-sunmi-keyboard-handlernpx cap sync

Modify your MainActivity.java file to include the following:

package com.example.plugin;

import android.view.KeyEvent;

import com.getcapacitor.BridgeActivity;

import dev.duma.capacitor.sunmikeyboardhandler.HasKeyHandlersInterface;
import dev.duma.capacitor.sunmikeyboardhandler.KeyHandlerInterface;

public class MainActivity extends BridgeActivity implements HasKeyHandlersInterface {
    private KeyHandlerInterface keyHandler = null;

    public KeyHandlerInterface getKeyHandler() {
        return keyHandler;
    }

    public void setKeyHandler(KeyHandlerInterface keyHandler) {
        this.keyHandler = keyHandler;
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        KeyHandlerInterface handler = getKeyHandler();

        if (handler != null && handler.handle(event)) return true;

        return super.dispatchKeyEvent(event);
    }
}

API

Latest API documentation can be found in readme file on GitHub

setKeyHandler(...)

setKeyHandler(options: { key: HandleableKey; }, callback: KeyHandlerCallback) => Promise<CallbackID>

Set a callback to be called when a key specified in key parameter is pressed.

ParamType
options{ key: HandleableKey; }
callbackKeyHandlerCallback

Returns: Promise<string>


removeKeyHandler(...)

removeKeyHandler(options: { key: HandleableKey; }) => Promise<void>

Remove a callback set by setKeyHandler for a key specified in key parameter.

ParamType
options{ key: HandleableKey; }

setBarcodeHandler(...)

setBarcodeHandler(callback: BarcodeHandlerCallback) => Promise<CallbackID>

Set a callback to be called when a barcode is scanned.

ParamType
callbackBarcodeHandlerCallback

Returns: Promise<string>


removeBarcodeHandler()

removeBarcodeHandler() => Promise<void>

Remove a callback set by setBarcodeHandler.


setDebugHandler(...)

setDebugHandler(callback: DebugHandlerCallback) => Promise<CallbackID>

Set a callback to be called when any unhandled key is pressed.

ParamType
callbackDebugHandlerCallback

Returns: Promise<string>


removeDebugHandler()

removeDebugHandler() => Promise<void>

Remove a callback set by setDebugHandler.


Type Aliases

KeyHandlerCallback

(data: { key: HandleableKey; modifiers: ModifierKey; type: KeyEvent; }): void

CallbackID

string

BarcodeHandlerCallback

(data: { barcode: string; device: { type: string; id: number; }; }): void

DebugHandlerCallback

(data: any): void

Enums

HandleableKey

MembersValue
Esc"ESC"
F1"F1"
F2"F2"
F3"F3"
F4"F4"
F5"F5"
F6"F6"
F7"F7"
F8"F8"
F9"F9"
F10"F10"
Delete"DELETE"
Home"HOME"
End"END"
PgUp"PGUP"
PgDn"PGDN"
Cash"CASH"
L2s_Shortcut_or_RFID"L2S_SHORTCUT_OR_RFID"

ModifierKey

MembersValue
Alt"ALT"
Ctrl"CTRL"
Shift"SHIFT"

KeyEvent

MembersValue
KeyDown"KEY_DOWN"
KeyUp"KEY_UP"