Added in API level 3
Deprecated in API level 29

Key


open class Key
kotlin.Any
   ↳ android.inputmethodservice.Keyboard.Key

Class for describing the position and characteristics of a single key in the keyboard.

Summary

XML attributes
android:codes The unicode value or comma-separated values that this key outputs.
android:horizontalGap Default horizontal gap between keys.
android:iconPreview The icon to show in the popup preview.
android:isModifier Whether this is a modifier key such as Alt or Shift.
android:isRepeatable Whether long-pressing on this key will make it repeat.
android:isSticky Whether this is a toggle key.
android:keyEdgeFlags Key edge flags.
android:keyHeight Default height of a key, in pixels or percentage of display width.
android:keyIcon The icon to display on the key instead of the label.
android:keyLabel The label to display on the key.
android:keyOutputText The string of characters to output when this key is pressed.
android:keyWidth Default width of a key, in pixels or percentage of display width.
android:popupCharacters The characters to display in the popup keyboard.
android:popupKeyboard The XML keyboard layout of any popup keyboard.
Public constructors
Key(parent: Keyboard.Row!)

Create an empty key with no attributes.

Key(res: Resources!, parent: Keyboard.Row!, x: Int, y: Int, parser: XmlResourceParser!)

Create a key with the given top-left coordinate and extract its attributes from the XML parser.

Public methods
open IntArray!

Returns the drawable state for the key, based on the current state and type of the key.

open Boolean
isInside(x: Int, y: Int)

Detects if a point falls inside this key.

open Unit

Informs the key that it has been pressed, in case it needs to change its appearance or state.

open Unit

Changes the pressed state of the key.

open Int

Returns the square of the distance between the center of the key and the given point.

Properties
IntArray!

All the key codes (unicode or custom code) that this key could generate, zero'th being the most important.

Int

Flags that specify the anchoring to edges of the keyboard for detecting touch events that are just out of the boundary of the key.

Int

The horizontal gap before this key

Int

Height of the key, not including the gap

Drawable!

Icon to display instead of a label.

Drawable!

Preview version of the icon, for the preview popup

CharSequence!

Label to display

Boolean

Whether this is a modifier key, such as Shift or Alt

Boolean

If this is a sticky key, is it on?

CharSequence!

Popup characters

Int

If this key pops up a mini keyboard, this is the resource id for the XML layout for that keyboard.

Boolean

The current pressed state of this key

Boolean

Whether this key repeats itself when held down

Boolean

Whether this key is sticky, i.

CharSequence!

Text to output when pressed.

Int

Width of the key, not including the gap

Int

X coordinate of the key in the keyboard layout

Int

Y coordinate of the key in the keyboard layout

XML attributes

android:codes

android:codes
The unicode value or comma-separated values that this key outputs. {@deprecated Copy this definition into your own application project.}

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

May be an integer value, such as "100".

android:horizontalGap

android:horizontalGap
Default horizontal gap between keys. {@deprecated Copy this definition into your own application project.}

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

android:iconPreview

android:iconPreview
The icon to show in the popup preview. {@deprecated Copy this definition into your own application project.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:isModifier

android:isModifier
Whether this is a modifier key such as Alt or Shift. {@deprecated Copy this definition into your own application project.}

May be a boolean value, such as "true" or "false".

android:isRepeatable

android:isRepeatable
Whether long-pressing on this key will make it repeat. {@deprecated Copy this definition into your own application project.}

May be a boolean value, such as "true" or "false".

android:isSticky

android:isSticky
Whether this is a toggle key. {@deprecated Copy this definition into your own application project.}

May be a boolean value, such as "true" or "false".

android:keyEdgeFlags

android:keyEdgeFlags
Key edge flags. {@deprecated Copy this definition into your own application project.}

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
left 1 Key is anchored to the left of the keyboard. {@deprecated Copy this definition into your own application project.}
right 2 Key is anchored to the right of the keyboard. {@deprecated Copy this definition into your own application project.}

android:keyHeight

android:keyHeight
Default height of a key, in pixels or percentage of display width. {@deprecated Copy this definition into your own application project.}

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

android:keyIcon

android:keyIcon
The icon to display on the key instead of the label. {@deprecated Copy this definition into your own application project.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:keyLabel

android:keyLabel
The label to display on the key. {@deprecated Copy this definition into your own application project.}

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:keyOutputText

android:keyOutputText
The string of characters to output when this key is pressed. {@deprecated Copy this definition into your own application project.}

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:keyWidth

android:keyWidth
Default width of a key, in pixels or percentage of display width. {@deprecated Copy this definition into your own application project.}

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

May be a fractional value, which is a floating point number appended with either % or %p, such as "14.5%". The % suffix always means a percentage of the base size; the optional %p suffix provides a size relative to some parent container.

android:popupCharacters

android:popupCharacters
The characters to display in the popup keyboard. {@deprecated Copy this definition into your own application project.}

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

android:popupKeyboard

android:popupKeyboard
The XML keyboard layout of any popup keyboard. {@deprecated Copy this definition into your own application project.}

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

Public constructors

Key

Added in API level 3
Key(parent: Keyboard.Row!)

Create an empty key with no attributes.

Key

Added in API level 3
Key(
    res: Resources!,
    parent: Keyboard.Row!,
    x: Int,
    y: Int,
    parser: XmlResourceParser!)

Create a key with the given top-left coordinate and extract its attributes from the XML parser.

Parameters
res Resources!: resources associated with the caller's context
parent Keyboard.Row!: the row that this key belongs to. The row must already be attached to a Keyboard.
x Int: the x coordinate of the top-left
y Int: the y coordinate of the top-left
parser XmlResourceParser!: the XML parser containing the attributes for this key

Public methods

getCurrentDrawableState

Added in API level 3
open fun getCurrentDrawableState(): IntArray!

Deprecated: Deprecated in Java.

Returns the drawable state for the key, based on the current state and type of the key.

Return
IntArray! the drawable state of the key.

isInside

Added in API level 3
open fun isInside(
    x: Int,
    y: Int
): Boolean

Deprecated: Deprecated in Java.

Detects if a point falls inside this key.

Parameters
x Int: the x-coordinate of the point
y Int: the y-coordinate of the point
Return
Boolean whether or not the point falls inside the key. If the key is attached to an edge, it will assume that all points between the key and the edge are considered to be inside the key.

onPressed

Added in API level 3
open fun onPressed(): Unit

Deprecated: Deprecated in Java.

Informs the key that it has been pressed, in case it needs to change its appearance or state.

onReleased

Added in API level 3
open fun onReleased(inside: Boolean): Unit

Deprecated: Deprecated in Java.

Changes the pressed state of the key.

Toggled state of the key will be flipped when all the following conditions are fulfilled:

Parameters
inside Boolean: whether the finger was released inside the key. Works only on Android M and later. See the method document for details.

See Also

squaredDistanceFrom

Added in API level 3
open fun squaredDistanceFrom(
    x: Int,
    y: Int
): Int

Deprecated: Deprecated in Java.

Returns the square of the distance between the center of the key and the given point.

Parameters
x Int: the x-coordinate of the point
y Int: the y-coordinate of the point
Return
Int the square of the distance of the point from the center of the key

Properties

codes

Added in API level 3
var codes: IntArray!

Deprecated: Deprecated in Java.

All the key codes (unicode or custom code) that this key could generate, zero'th being the most important.

edgeFlags

Added in API level 3
var edgeFlags: Int

Deprecated: Deprecated in Java.

Flags that specify the anchoring to edges of the keyboard for detecting touch events that are just out of the boundary of the key. This is a bit mask of Keyboard#EDGE_LEFT, Keyboard#EDGE_RIGHT, Keyboard#EDGE_TOP and Keyboard#EDGE_BOTTOM.

gap

Added in API level 3
var gap: Int

Deprecated: Deprecated in Java.

The horizontal gap before this key

height

Added in API level 3
var height: Int

Deprecated: Deprecated in Java.

Height of the key, not including the gap

icon

Added in API level 3
var icon: Drawable!

Deprecated: Deprecated in Java.

Icon to display instead of a label. Icon takes precedence over a label

iconPreview

Added in API level 3
var iconPreview: Drawable!

Deprecated: Deprecated in Java.

Preview version of the icon, for the preview popup

label

Added in API level 3
var label: CharSequence!

Deprecated: Deprecated in Java.

Label to display

modifier

Added in API level 3
var modifier: Boolean

Deprecated: Deprecated in Java.

Whether this is a modifier key, such as Shift or Alt

on

Added in API level 3
var on: Boolean

Deprecated: Deprecated in Java.

If this is a sticky key, is it on?

popupCharacters

Added in API level 3
var popupCharacters: CharSequence!

Deprecated: Deprecated in Java.

Popup characters

popupResId

Added in API level 3
var popupResId: Int

Deprecated: Deprecated in Java.

If this key pops up a mini keyboard, this is the resource id for the XML layout for that keyboard.

pressed

Added in API level 3
var pressed: Boolean

Deprecated: Deprecated in Java.

The current pressed state of this key

repeatable

Added in API level 3
var repeatable: Boolean

Deprecated: Deprecated in Java.

Whether this key repeats itself when held down

sticky

Added in API level 3
var sticky: Boolean

Deprecated: Deprecated in Java.

Whether this key is sticky, i.e., a toggle key

text

Added in API level 3
var text: CharSequence!

Deprecated: Deprecated in Java.

Text to output when pressed. This can be multiple characters, like ".com"

width

Added in API level 3
var width: Int

Deprecated: Deprecated in Java.

Width of the key, not including the gap

x

Added in API level 3
var x: Int

Deprecated: Deprecated in Java.

X coordinate of the key in the keyboard layout

y

Added in API level 3
var y: Int

Deprecated: Deprecated in Java.

Y coordinate of the key in the keyboard layout