Keyboard
Como usar:
<Keyboard />
<script>
export default {
components: {
Keyboard: '@mamba/keyboard/Keyboard.html',
},
};
</script>
Eventos
interface KeyboardTypeEvents {
onRender?: (instance: Keyboard) => void;
onInit?: (instance: Keyboard) => void;
onChange?: (input: string, e?: KeyboardHandlerEvent) => void;
onKeyPress?: (button: string, e?: KeyboardHandlerEvent) => void;
onFunctionKeyPress?: (button: string, instance: Keyboard, e?: KeyboardHandlerEvent) => void;
}
Opções
interface KeyboardOptions {
keyboardType?: KeyboardType;
layout?: KeyboardLayoutObject;
layoutName?: string;
layoutDirection?: LayoutDirection;
theme?: string;
labels?: { [button: string]: string };
outputs?: { [button: string]: string };
activeButtonClass?: string;
hiddenKeyboardClass?: string;
debug?: boolean;
maxLength?: any;
disableCaretPositioning?: boolean;
inputPattern?: RegExp;
excludeFromLayout?: { [layoutName: string]: string[] };
allowKeySyntheticEvent?: string[];
input?: KeyboardInputOption;
updateMode?: KeyboardUpdateMode;
keepVisible?: boolean;
lockCursor?: boolean;
autoRender?: boolean;
soundEnabled?: boolean;
beepTone?: BeepTone;
beepTime?: number;
enableLayoutSuggestions?: boolean;
layoutSuggestions?: { [key: string]: [string?, string?, string?, string?] };
[name: string]: any;
}
Teclados predisponíveis
enum KeyboardType {
Default = 'default',
Numeric = 'numeric',
Phone = 'phone',
Math = 'math',
Custom = 'custom',
}
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.setOptions({
keyboardType: 'numeric',
});
Ou use um dos métodos prontos:
◼︎ Default (alfanumérico)
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.setKeyboardAsDefaultType();
◼︎ Numérico
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.setKeyboardAsNumericType();
◼︎ Calculadora
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.setKeyboardAsMathType();
◼︎ Telefone (Number pad)
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.setKeyboardAsPhoneType();
API
Responsável por expor métodos de controle sobre o teclado, bem como métodos de ajuda auxiliares, e acesso aos métodos do teclado virtual e seus métodos derivados.
Interface
interface Keyboard {
virtualKeyboard: Keyboard;
visibility: KeyboardVisibility;
setKeyboardInputAsNumeric: () => void;
setKeyboardInputAsAlphanumeric: () => void;
getKeyCode: (keyName: string) => number;
getKeyName: (keyCode: number) => string;
isNumericKey: (keyCode: number) => boolean;
isActionKey: (keyCode: number) => boolean;
isBackspaceEnabled: () => boolean;
disableBackspace: () => void;
enableBackspace: () => void;
setOptions(options?: {}): void;
setInput(input: string): void;
getInput(): string;
clearInput(): void;
replaceInput(keyboardInput: { default: string }): void;
render(): void;
show(): void;
unmount(): void;
currentInputPatternIsValid(): boolean;
getButtonElement(button: string): undefined | KeyboardElement | KeyboardElement[];
setKeyboardAsCustomType(otherOptions?: {}): void;
setKeyboardAsDefaultType(): void;
setKeyboardAsMathType(): void;
setKeyboardAsNumericType(): void;
setKeyboardAsPhoneType(): void;
}
setKeyboardInputAsNumeric()
Define que a máquina irá digitar apenas números.
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.setKeyboardInputAsNumeric();
setKeyboardInputAsAlphanumeric()
Define que a máquina irá digitar caracteres alfanuméricos.
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.setKeyboardInputAsAlphanumeric();
getKeyCode(keyName)
Retorna o código da tecla
referente a uma tecla da máquina.
import Keyboard from '@mamba/keyboard/api/index.js'
Keyboard.getKeyCode('Enter');
Keyboard.getKeyCode('Back');
Keyboard.getKeyCode('Close');
Keyboard.getKeyCode('Help');
Keyboard.getKeyCode('Shortcuts');
Keyboard.getKeyCode('0');
...
Keyboard.getKeyCode('9');
getKeyName(keyCode)
Retorna o nome da tecla
referente ao código de uma tecla da máquina.
import Keyboard from '@mamba/keyboard/api/index.js'
Keyboard.getKeyName(13);
Keyboard.getKeyName(8);
Keyboard.getKeyName(27);
Keyboard.getKeyName(17);
Keyboard.getKeyName(16);
Keyboard.getKeyName(48);
...
Keyboard.getKeyName(57);
isNumericKey(keyCode)
Retorna se uma tecla representa um número.
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.isNumericKey(13);
Keyboard.isNumericKey(57);
isActionKey(keyCode)
(Obsoleto, usar isFunctionKey()
)
Retorna se uma tecla representa uma ação.
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.isActionKey(13);
Keyboard.isActionKey(57);
isFunctionKey(keyCode)
Retorna se uma tecla representa uma ação.
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.isFunctionKey(13);
Keyboard.isFunctionKey(57);
isBackspaceEnabled()
Retorna se o uso do botão de voltar
/backspace
está habilitado ou não no aplicativo.
disableBackspace()
Desabilita o uso do botão de voltar
/backspace
no aplicativo em questão.
enableBackspace()
Habilita o uso do botão de voltar
/backspace
no aplicativo em questão.
import Keyboard from '@mamba/keyboard/api/index.js';
Keyboard.isBackspaceEnabled();
Keyboard.disableBackspace();
Keyboard.isBackspaceEnabled();
Keyboard.enableBackspace();
Keyboard native key map
Para usar as teclas nativas do teclado (teclado físico POS), você precisa instalar @mamba/core
.
O objeto KEYBOARD
fornece os mapas de teclas e nomes de teclas específicos do POS.
import { KEYBOARD } from '@mamba/core';
See @mamba/core Docs for more info.