@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
setKeyHandler(...)
setKeyHandler(options: { key: HandleableKey; }, callback: KeyHandlerCallback) => Promise<CallbackID>
Set a callback to be called when a key specified in key
parameter is pressed.
Param | Type |
---|---|
options | { key: HandleableKey; } |
callback | KeyHandlerCallback |
Returns: Promise<string>
removeKeyHandler(...)
removeKeyHandler(options: { key: HandleableKey; }) => Promise<void>
Remove a callback set by setKeyHandler
for a key specified in key
parameter.
Param | Type |
---|---|
options | { key: HandleableKey; } |
setBarcodeHandler(...)
setBarcodeHandler(callback: BarcodeHandlerCallback) => Promise<CallbackID>
Set a callback to be called when a barcode is scanned.
Param | Type |
---|---|
callback | BarcodeHandlerCallback |
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.
Param | Type |
---|---|
callback | DebugHandlerCallback |
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
Members | Value |
---|---|
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
Members | Value |
---|---|
Alt | "ALT" |
Ctrl | "CTRL" |
Shift | "SHIFT" |
KeyEvent
Members | Value |
---|---|
KeyDown | "KEY_DOWN" |
KeyUp | "KEY_UP" |