Skip to content

Android TV key mapping ​

Every toets key is a real Android KeyEvent injected into the system input pipeline, so the app's native focus engine handles it exactly like a remote button. D-pad keys and SELECT come from the D-pad input source (SOURCE_DPAD), like a remote's: a focused EditText takes keyboard-source arrows as caret moves and never lets focus leave, while D-pad arrows move focus out of it.

KeyAndroid keycodeCapability
UP DOWN LEFT RIGHTDPAD_UP 19 ... DPAD_RIGHT 22-
SELECTDPAD_CENTER 23-
BACKBACK 4key.back
HOMEHOME 3key.home
MENUMENU 82key.menu
INFOINFO 165key.info
PLAY_PAUSEMEDIA_PLAY_PAUSE 85key.media.toggle
PLAY PAUSE STOPMEDIA_PLAY 126, MEDIA_PAUSE 127, MEDIA_STOP 86key.media.discrete
FAST_FORWARD REWINDMEDIA_FAST_FORWARD 90, MEDIA_REWIND 89key.media.seek
NEXT PREVIOUSMEDIA_NEXT 87, MEDIA_PREVIOUS 88key.media.track
RED GREEN YELLOW BLUEPROG_RED 183 ... PROG_BLUE 186key.color
CHANNEL_UP CHANNEL_DOWNCHANNEL_UP 166, CHANNEL_DOWN 167key.channel
DIGIT_0 ... DIGIT_90 7 ... 9 16key.numeric

The table is ANDROID_KEYCODES. Which of these a target claims depends on the remote option: android-tv (default) claims all of them, fire-tv only what the Fire TV remote has (see Fire TV).

Long press ​

app.remote.longPress(key, holdMs) holds the key for exactly holdMs the way a held remote button does: key down, auto-repeat downs from the system long-press timeout (the first flagged FLAG_LONG_PRESS) every 50 ms, then key up. Apps see isLongPress(), onKeyLongPress and growing repeatCount, so hold-to-scrub works.

UiAutomator2 cannot hold keys, so holds run through a 2 KB helper the driver pushes to /data/local/tmp and starts with app_process. A hold costs about 1 s on top of holdMs (helper start-up).

Trap ​

On Android SELECT is DPAD_CENTER, not ENTER. Apps that only handle KEYCODE_ENTER work with keyboards but not with remotes; toets tests the remote.