public class

KeyboardManager

extends Object
java.lang.Object
   ↳ com.datalogic.device.input.KeyboardManager

Class Overview

This class provides access to keyboard related methods of the device.

Summary

Nested Classes
class KeyboardManager.VScanCode Virtual key scan codes. 
Constants
String ARG_LONG_PRESS_TIMEOUT An argument for changing the behavior of LONG_PRESS_TIMED_OUT, configure the duration in milliseconds before a press turns into a long press.
String ARG_MULTIPLE_PRESS_COUNT An argument for changing the behavior of MULTIPLE_PRESS_UP, configure the number of presses for multiple press detection.
String ARG_MULTIPLE_PRESS_MAX_BREAK An argument for changing the behavior of MULTIPLE_PRESS_UP, configure the maximum break time between consecutive presses of a multiple press (in milliseconds).
String ARG_MULTIPLE_PRESS_MAX_INTERVAL An argument for changing the behavior of MULTIPLE_PRESS_UP, configure the maximum interval between DOWN and UP of a multiple press (in milliseconds).
String ARG_VERY_LONG_PRESS_TIMEOUT An argument for changing the behavior of VERY_LONG_PRESS_TIMED_OUT, configure the duration in milliseconds before a press turns into a very long press.
int TRIGGER_ID_AUTOSCAN ID for AutoScan trigger.
int TRIGGER_ID_FRONT ID for Front trigger.
int TRIGGER_ID_LEFT ID for Left trigger.
int TRIGGER_ID_MOTION ID for Motion trigger.
int TRIGGER_ID_PISTOL ID for Pistol trigger.
int TRIGGER_ID_RIGHT ID for Right trigger.
Public Constructors
KeyboardManager()
This is the constructor of KeyboardManager.
Public Methods
int clearAllMappings()
Removes all the configured mappings.
int clearMapping(VScanEntry scanCode)
Removes a single active mapping.
int disableKey(VScanEntry scanCode, boolean disable)
Disables completely a single physical key, through the VScanEntry data structure.
AdvancedKeyboard getAdvancedKeyboard()
Returns the AdvancedKeyboard object, which can be used to customize the keyboard configuration, read info about the currently installed keyboard and listen to some keyboard events.
List<VScanEntry> getAllMappedScanEntries()
Retrieve all mapped scan codes.
List<Trigger> getAvailableTriggers()
Returns the available triggers in the device.
Intent getIntent(VScanEntry scanCode)
Returns current mapping between a physical key and an Intent.
KeyCodeEntry getKeyCode(VScanEntry scanCode)
Returns current mapping between a physical scan code key and an Android key code.
static int[][] getKeyboardLayout()
Returns the physical keyboard layout.
Map<VScanEntry, Intent> getMappedIntents()
Provides a Map< VScanEntry, android.content.Intent > containing all the stored and active Android Intent mappings.
Map<VScanEntryKeyCodeEntry> getMappedKeyCodes()
Provides a Map< VScanEntry, KeyCodeEntry> containing all the stored and active Android key codes mappings.
Map<VScanEntry, Character> getMappedUnicodes()
Provides a Map< VScanEntry, Character> containing all the stored and active Character mappings.
Map<String, String> getMappingArguments(VScanEntry scanCode)
Gets the arguments of a key mapping.
Map<MappingTriggerPolicyMappingObject> getMappingObjects(VScanEntry scanCode)
Query the mapping information of a key.
Character getUnicode(VScanEntry scanCode)
Returns current mapping between a physical key and a unicode character.
boolean isInputLocked()
Tells if the input from keyboard is locked.
boolean isKeyDisabled(VScanEntry scanCode)
Checks if a physical key is disabled.
int lockInput(boolean lock)
Locks or unlocks the input from keyboard and physical buttons.
int mapIntent(VScanEntry scanCode, Intent intent)
Assigns an Intent to a physical key.
int mapKey(VScanEntry scanCode, Map<MappingTriggerPolicyMappingObject> mappingInfo, Map<String, String> arguments)
Maps key events to customized actions.
int mapKey(VScanEntry scanCode, Map<MappingTriggerPolicyMappingObject> mappingInfo)
Maps key events to customized actions.
int mapKeyCode(VScanEntry scanCode, KeyCodeEntry keyCode)
Assigns a virtual key code to a physical key.
int mapUnicode(VScanEntry scanCode, Character c)
Assigns a unicode character to a physical key.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ARG_LONG_PRESS_TIMEOUT

Added in revision 35

An argument for changing the behavior of LONG_PRESS_TIMED_OUT, configure the duration in milliseconds before a press turns into a long press.
Used as a map entry key to configure arguments in mapKey(VScanEntry, Map, Map)
Default value: 500 (ms)

Constant Value: "long_press_timeout"

public static final String ARG_MULTIPLE_PRESS_COUNT

Added in revision 35

An argument for changing the behavior of MULTIPLE_PRESS_UP, configure the number of presses for multiple press detection.
Used as a map entry key to configure arguments in mapKey(VScanEntry, Map, Map)
Default value: 2

Constant Value: "multiple_press_count"

public static final String ARG_MULTIPLE_PRESS_MAX_BREAK

Added in revision 35

An argument for changing the behavior of MULTIPLE_PRESS_UP, configure the maximum break time between consecutive presses of a multiple press (in milliseconds).
Used as map entry key to configure arguments in mapKey(VScanEntry, Map, Map)
Default value: 200 (ms)

Constant Value: "multiple_press_max_break"

public static final String ARG_MULTIPLE_PRESS_MAX_INTERVAL

Added in revision 35

An argument for changing the behavior of MULTIPLE_PRESS_UP, configure the maximum interval between DOWN and UP of a multiple press (in milliseconds).
Used as a map entry key to configure arguments in mapKey(VScanEntry, Map, Map)
Default value: 200 (ms)

Constant Value: "multiple_press_max_interval"

public static final String ARG_VERY_LONG_PRESS_TIMEOUT

Added in revision 35

An argument for changing the behavior of VERY_LONG_PRESS_TIMED_OUT, configure the duration in milliseconds before a press turns into a very long press.
Used as a map entry key to configure arguments in mapKey(VScanEntry, Map, Map)
Default value: 5000 (ms)

Constant Value: "very_long_press_timeout"

public static final int TRIGGER_ID_AUTOSCAN

Added in revision 5

ID for AutoScan trigger.

Constant Value: 4 (0x00000004)

public static final int TRIGGER_ID_FRONT

Added in revision 5

ID for Front trigger.

Constant Value: 3 (0x00000003)

public static final int TRIGGER_ID_LEFT

Added in revision 5

ID for Left trigger.

Constant Value: 0 (0x00000000)

public static final int TRIGGER_ID_MOTION

Added in revision 11

ID for Motion trigger.

Constant Value: 5 (0x00000005)

public static final int TRIGGER_ID_PISTOL

Added in revision 5

ID for Pistol trigger.

Constant Value: 2 (0x00000002)

public static final int TRIGGER_ID_RIGHT

Added in revision 5

ID for Right trigger.

Constant Value: 1 (0x00000001)

Public Constructors

public KeyboardManager ()

Added in revision 1

This is the constructor of KeyboardManager.

Throws
DeviceException in case of error.

Public Methods

public int clearAllMappings ()

Added in revision 1

Removes all the configured mappings. Whenever this method is called, all the current active mappings are cleared and removed.

Returns
  • int SUCCESS in case of success, otherwise a possible error code, matching one of the DeviceException error constants.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int clearMapping (VScanEntry scanCode)

Added in revision 1

Removes a single active mapping. The current active mapping for the selected VScanEntry, if existing, is removed.

Parameters
scanCode a VScanEntry representing the virtual scan code, mapped that must be removed.
Returns
  • int SUCCESS in case of success, otherwise a possible error code, matching one of the DeviceException error constants.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int disableKey (VScanEntry scanCode, boolean disable)

Added in revision 1

Disables completely a single physical key, through the VScanEntry data structure. When a key is disabled, no input will be produced whenever key presses are detected. When a key is again re-enabled, is reset to its original value, so any previous mapping is automatically lost.

Parameters
scanCode a VScanEntry representing the virtual scan code, associated to the physical key.
disable a boolean that specifies whether or not the key will be disabled.
Returns
  • int SUCCESS in case of success, otherwise a possible error code, matching one of the DeviceException error constants.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public AdvancedKeyboard getAdvancedKeyboard ()

Added in revision 22

Returns the AdvancedKeyboard object, which can be used to customize the keyboard configuration, read info about the currently installed keyboard and listen to some keyboard events.

Returns
  • AdvancedKeyboard object if the device supports it, otherwise it throws an exception if exceptions are enabled through the ErrorManager singleton or null if exceptions are disabled.
Throws
DeviceException in case of unsupported device, when exceptions are enabled through the ErrorManager singleton.

public List<VScanEntry> getAllMappedScanEntries ()

Added in revision 35

Retrieve all mapped scan codes. This method returns a list of all mapped scan codes. You may query the mapping information of each scan codes in the returned list by using getMappingObjects(VScanEntry)

Returns
  • a list of mapped scan codes. An empty list is returned if there is no mapping.

public List<Trigger> getAvailableTriggers ()

Added in revision 5

Returns the available triggers in the device.

Returns
  • List of Trigger objects, each representing one of the supported triggers.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public Intent getIntent (VScanEntry scanCode)

Added in revision 1

Returns current mapping between a physical key and an Intent.

Parameters
scanCode a VScanEntry representing the virtual scan code.
Returns
  • Intent used to launch an Android activity through the Context.startActivity(Intent intent) method. Returns null in case there is no association.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.
See Also

public KeyCodeEntry getKeyCode (VScanEntry scanCode)

Added in revision 1

Returns current mapping between a physical scan code key and an Android key code.

Parameters
scanCode a VScanEntry representing the virtual scan code.
Returns
  • KeyCodeEntry representing an Android key code and meta state. Returns null in case there is no association.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public static int[][] getKeyboardLayout ()

Added in revision 1

Returns the physical keyboard layout. It can be used by application for keyboard remapping.

Returns
  • Cubic grid of scan codes, representing the physical keyboard present. If a row does not span the entire length, 0's or -1's will fill those spots.

public Map<VScanEntry, Intent> getMappedIntents ()

Added in revision 1

Provides a Map< VScanEntry, android.content.Intent > containing all the stored and active Android Intent mappings.

Returns
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public Map<VScanEntryKeyCodeEntry> getMappedKeyCodes ()

Added in revision 1

Provides a Map< VScanEntry, KeyCodeEntry> containing all the stored and active Android key codes mappings.

Returns
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public Map<VScanEntry, Character> getMappedUnicodes ()

Added in revision 1

Provides a Map< VScanEntry, Character> containing all the stored and active Character mappings.

Returns
  • Map< VScanEntry, Character> the corresponding saved mappings. Null is returned if there aren't any mappings saved.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public Map<String, String> getMappingArguments (VScanEntry scanCode)

Added in revision 35

Gets the arguments of a key mapping. Using this method to retrieve the arguments that you have passed to mapKey(VScanEntry, Map, Map) as the third parameter.

Parameters
scanCode scan code to look for key mapping
Returns
  • the key mapping arguments

public Map<MappingTriggerPolicyMappingObject> getMappingObjects (VScanEntry scanCode)

Added in revision 35

Query the mapping information of a key. Using this method to retrieve the mapping information that you have passed to mapKey(VScanEntry, Map, Map) as the second parameter.

Parameters
scanCode scan code to look for key mapping
Returns
  • the mapping information

public Character getUnicode (VScanEntry scanCode)

Added in revision 1

Returns current mapping between a physical key and a unicode character.

Parameters
scanCode a VScanEntry representing the virtual scan code.
Returns
  • unicode character. Returns null in case there is no association.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.
See Also

public boolean isInputLocked ()

Added in revision 1

Tells if the input from keyboard is locked.

Returns
  • boolean it returns whether or not the keyboard is locked.

public boolean isKeyDisabled (VScanEntry scanCode)

Added in revision 5

Checks if a physical key is disabled.

Parameters
scanCode a VScanEntry representing the virtual scan code, associated to the physical key.
Returns
  • boolean True in case the key is disabled, false otherwise or in case of error.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int lockInput (boolean lock)

Added in revision 1

Locks or unlocks the input from keyboard and physical buttons.

Parameters
lock boolean it specifies whether or not the keyboard will be locked.
Returns
  • int SUCCESS in case of success, otherwise a possible error code, matching one of the DeviceException error constants.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int mapIntent (VScanEntry scanCode, Intent intent)

Added in revision 1

Assigns an Intent to a physical key. If a mapping for the desired physical key is already assigned and saved, it will be overridden.

Parameters
scanCode a VScanEntry representing the virtual scan code.
intent Intent used to launch an Android activity through the Context.startActivity(Intent intent) method.

Example code to make Camera Activity capture an image on the front scan trigger pressure:
(new KeyboardManager()).mapIntent(new VScanEntry(VScanCode.VSCAN_FRONT_TRIGGER), new Intent(MediaStore.ACTION_IMAGE_CAPTURE));

Example code to make BarcodeManager capture a barcode on the front scan trigger pressure and to stop capturing on the front scan trigger release:
(new KeyboardManager()).mapIntent(new VScanEntry(VScanCode.VSCAN_FRONT_TRIGGER), new Intent(BarcodeManager.ACTION_START_DECODE));

Returns
  • int SUCCESS in case of success, otherwise a possible error code, matching one of the DeviceException error constants.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.
See Also

public int mapKey (VScanEntry scanCode, Map<MappingTriggerPolicyMappingObject> mappingInfo, Map<String, String> arguments)

Added in revision 35

Maps key events to customized actions.
This is a generic way to map a key to customized actions.
The actions are defined by providing a map of MappingTriggerPolicy to MappingObject. For each entry in this map, the key defines a key events for detection and the value defines customized actions to be executed.
Optionally, you can also provide several arguments to change the way MappingTriggerPolicy is detected. For example, you may customize the long press timeout of LONG_PRESS_TIMED_OUT by providing ARG_LONG_PRESS_TIMEOUT argument.
For more information about possible arguments, see: ARG_LONG_PRESS_TIMEOUT, ARG_MULTIPLE_PRESS_COUNT, ARG_MULTIPLE_PRESS_MAX_BREAK, ARG_MULTIPLE_PRESS_MAX_INTERVAL

Parameters
scanCode a scan code to track events
mappingInfo a map defines the key events and the corresponding actions to be executed
arguments optional arguments to change the behavior of trigger policies
Returns
  • DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int mapKey (VScanEntry scanCode, Map<MappingTriggerPolicyMappingObject> mappingInfo)

Added in revision 35

Maps key events to customized actions.
This is a generic way to map a key to customized actions.
The actions are defined by providing a map of MappingTriggerPolicy to MappingObject. For each entry in this map, the key defines a key events for detection and the value defines customized actions to be executed.

Parameters
scanCode a scan code to track events
mappingInfo a map defines the key events and the corresponding actions to be executed
Returns
  • DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int mapKeyCode (VScanEntry scanCode, KeyCodeEntry keyCode)

Added in revision 1

Assigns a virtual key code to a physical key. If a mapping for the desired physical key is already assigned and saved, it will be overridden.

Parameters
scanCode a VScanEntry representing the virtual scan code.
keyCode a KeyCodeEntry representing the Android key code and meta state.

Example code to avoid any keyboard event on the left scan trigger pressure:
(new KeyboardManager()).mapKeyCode(new VScanEntry(VScanCode.VSCAN_LEFT_TRIGGER), new KeyCodeEntry(KeyEvent.KEYCODE_UNKNOWN));

Example code to map the left scan trigger to the Android left trigger button key code:
(new KeyboardManager()).mapKeyCode(new VScanEntry(VScanCode.VSCAN_LEFT_TRIGGER), new KeyCodeEntry(KeyEvent.KEYCODE_BUTTON_L1));

Example code to map the enter key to the Android home key code:
(new KeyboardManager()).mapKeyCode(new VScanEntry(VScanCode.VSCAN_RIGHT_ENTER), new KeyCodeEntry(KeyEvent.KEYCODE_HOME));

Returns
  • int SUCCESS in case of success, otherwise a possible error code, matching one of the DeviceException error constants.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.

public int mapUnicode (VScanEntry scanCode, Character c)

Added in revision 1

Assigns a unicode character to a physical key. If a mapping for the desired physical key is already assigned and saved, it will be overridden.

Parameters
scanCode a VScanEntry representing the virtual scan code.
c unicode character

Example code to assign a Thai unicode character to the physical key '1':
(new KeyboardManager()).mapUnicode(new VScanEntry(VScanCode.VSCAN_1), '\\u0e01');

Returns
  • int SUCCESS in case of success, otherwise a possible error code, matching one of the DeviceException error constants.
Throws
DeviceException in case of error, when exceptions are enabled through the ErrorManager singleton.
See Also