public class

KeyCharacterMap

extends Object
java.lang.Object
   ↳ android.view.KeyCharacterMap

Summary

Nested Classes
class KeyCharacterMap.KeyData  
Constants
int ALPHA A keyboard with all the letters, and maybe some numbers.
int BUILT_IN_KEYBOARD The id of the device's primary built in keyboard is always 0.
int COMBINING_ACCENT
int COMBINING_ACCENT_MASK Mask the return value from get(int, int) with this value to get a printable representation of the accent character of a "dead key."
char HEX_INPUT This private-use character is used to trigger Unicode character input by hex digits.
int NUMERIC A numeric (12-key) keyboard.
char PICKER_DIALOG_INPUT This private-use character is used to bring up a character picker for miscellaneous symbols.
int PREDICTIVE A keyboard with all the letters, but with more than one letter per key.
Public Methods
static boolean deviceHasKey(int keyCode)
Queries the framework about whether any physical keys exist on the device that are capable of producing the given key codes.
static boolean[] deviceHasKeys(int[] keyCodes)
int get(int keyCode, int meta)

Returns the Unicode character that the specified key would produce when the specified meta bits (see MetaKeyKeyListener) were active.

static int getDeadChar(int accent, int c)
Get the character that is produced by putting accent on the character c.
char getDisplayLabel(int keyCode)
Get the primary character for this key.
KeyEvent[] getEvents(char[] chars)
Get an array of KeyEvent objects that if put into the input stream could plausibly generate the provided sequence of characters.
boolean getKeyData(int keyCode, KeyCharacterMap.KeyData results)
Get the characters conversion data for a given keyCode.
int getKeyboardType()
Returns NUMERIC, PREDICTIVE or ALPHA.
char getMatch(int keyCode, char[] chars, int modifiers)
If one of the chars in the array can be generated by keyCode, return the char; otherwise return '\0'.
char getMatch(int keyCode, char[] chars)
char getNumber(int keyCode)
Gets the number or symbol associated with the key.
boolean isPrintingKey(int keyCode)
Does this character key produce a glyph?
static KeyCharacterMap load(int keyboard)
Protected Methods
void finalize()
Is called before the object's memory is being reclaimed by the VM.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int ALPHA

Since: API Level 1

A keyboard with all the letters, and maybe some numbers.

Constant Value: 3 (0x00000003)

public static final int BUILT_IN_KEYBOARD

Since: API Level 1

The id of the device's primary built in keyboard is always 0.

Constant Value: 0 (0x00000000)

public static final int COMBINING_ACCENT

Since: API Level 1

Constant Value: -2147483648 (0x80000000)

public static final int COMBINING_ACCENT_MASK

Since: API Level 1

Mask the return value from get(int, int) with this value to get a printable representation of the accent character of a "dead key."

Constant Value: 2147483647 (0x7fffffff)

public static final char HEX_INPUT

Since: API Level 1

This private-use character is used to trigger Unicode character input by hex digits.

Constant Value: 61184 (0x0000ef00)

public static final int NUMERIC

Since: API Level 1

A numeric (12-key) keyboard.

Constant Value: 1 (0x00000001)

public static final char PICKER_DIALOG_INPUT

Since: API Level 1

This private-use character is used to bring up a character picker for miscellaneous symbols.

Constant Value: 61185 (0x0000ef01)

public static final int PREDICTIVE

Since: API Level 1

A keyboard with all the letters, but with more than one letter per key.

Constant Value: 2 (0x00000002)

Public Methods

public static boolean deviceHasKey (int keyCode)

Since: API Level 3

Queries the framework about whether any physical keys exist on the device that are capable of producing the given key codes.

public static boolean[] deviceHasKeys (int[] keyCodes)

Since: API Level 3

public int get (int keyCode, int meta)

Since: API Level 1

Returns the Unicode character that the specified key would produce when the specified meta bits (see MetaKeyKeyListener) were active.

Returns 0 if the key is not one that is used to type Unicode characters.

If the return value has bit COMBINING_ACCENT set, the key is a "dead key" that should be combined with another to actually produce a character -- see getDeadChar(int, int) -- after masking with COMBINING_ACCENT_MASK.

public static int getDeadChar (int accent, int c)

Since: API Level 1

Get the character that is produced by putting accent on the character c. For example, getDeadChar('`', 'e') returns è.

public char getDisplayLabel (int keyCode)

Since: API Level 1

Get the primary character for this key. In other words, the label that is physically printed on it.

public KeyEvent[] getEvents (char[] chars)

Since: API Level 1

Get an array of KeyEvent objects that if put into the input stream could plausibly generate the provided sequence of characters. It is not guaranteed that the sequence is the only way to generate these events or that it is optimal.

Returns
  • an array of KeyEvent objects, or null if the given char array can not be generated using the current key character map.

public boolean getKeyData (int keyCode, KeyCharacterMap.KeyData results)

Since: API Level 1

Get the characters conversion data for a given keyCode.

Parameters
keyCode the keyCode to look for
results a KeyCharacterMap.KeyData that will be filled with the results.
Returns
  • whether the key was mapped or not. If the key was not mapped, results is not modified.

public int getKeyboardType ()

Since: API Level 1

Returns NUMERIC, PREDICTIVE or ALPHA.

public char getMatch (int keyCode, char[] chars, int modifiers)

Since: API Level 1

If one of the chars in the array can be generated by keyCode, return the char; otherwise return '\0'.

Parameters
keyCode the key code to look at
chars the characters to try to find
modifiers the modifier bits to prefer. If any of these bits are set, if there are multiple choices, that could work, the one for this modifier will be set.

public char getMatch (int keyCode, char[] chars)

Since: API Level 1

public char getNumber (int keyCode)

Since: API Level 1

Gets the number or symbol associated with the key. The character value is returned, not the numeric value. If the key is not a number, but is a symbol, the symbol is retuned.

public boolean isPrintingKey (int keyCode)

Since: API Level 1

Does this character key produce a glyph?

public static KeyCharacterMap load (int keyboard)

Since: API Level 1

Protected Methods

protected void finalize ()

Since: API Level 1

Is called before the object's memory is being reclaimed by the VM. This can only happen once the VM has detected, during a run of the garbage collector, that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override finalize() as required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize() will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection.

Throws
Throwable