From 3ea4de826d95c580c28d854c677ded0d15d220a8 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Sat, 19 Feb 2011 01:08:02 -0800 Subject: Add new axes for joysticks and mouse wheels. Added API on InputDevice to query the set of axes available. Added API on KeyEvent and MotionEvent to convert keycodes and axes to symbolic name strings for diagnostic purposes. Added API on KeyEvent to query if a given key code is a gamepad button. Added a new "axis" element to key layout files to specify the mapping between raw absolute axis values and motion axis ids. Expanded the axis bitfield to 64bits to allow for future growth. Modified the Makefile for keyboard prebuilts to run the keymap validation tool during the build. Added layouts for two game controllers. Added default actions for game pad button keys. Added more tests. Fixed a bunch of bugs. Change-Id: I73f9166c3b3c5bcf4970845b58088ad467525525 --- libs/ui/Keyboard.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'libs/ui/Keyboard.cpp') diff --git a/libs/ui/Keyboard.cpp b/libs/ui/Keyboard.cpp index 6faa600e6e..8b6300a1ee 100644 --- a/libs/ui/Keyboard.cpp +++ b/libs/ui/Keyboard.cpp @@ -217,7 +217,7 @@ status_t getKeyCharacterMapFile(int32_t deviceId, String8& outKeyCharacterMapFil return NAME_NOT_FOUND; } -static int lookupLabel(const char* literal, const KeycodeLabel *list) { +static int lookupValueByLabel(const char* literal, const KeycodeLabel *list) { while (list->literal) { if (strcmp(literal, list->literal) == 0) { return list->value; @@ -227,12 +227,30 @@ static int lookupLabel(const char* literal, const KeycodeLabel *list) { return list->value; } +static const char* lookupLabelByValue(int value, const KeycodeLabel *list) { + while (list->literal) { + if (list->value == value) { + return list->literal; + } + list++; + } + return NULL; +} + int32_t getKeyCodeByLabel(const char* label) { - return int32_t(lookupLabel(label, KEYCODES)); + return int32_t(lookupValueByLabel(label, KEYCODES)); } uint32_t getKeyFlagByLabel(const char* label) { - return uint32_t(lookupLabel(label, FLAGS)); + return uint32_t(lookupValueByLabel(label, FLAGS)); +} + +int32_t getAxisByLabel(const char* label) { + return int32_t(lookupValueByLabel(label, AXES)); +} + +const char* getAxisLabel(int32_t axisId) { + return lookupLabelByValue(axisId, AXES); } static int32_t setEphemeralMetaState(int32_t mask, bool down, int32_t oldMetaState) { -- cgit v1.2.3-59-g8ed1b