summaryrefslogtreecommitdiff
path: root/libs/ui/Keyboard.cpp
diff options
context:
space:
mode:
author Jeff Brown <jeffbrown@google.com> 2011-02-19 01:08:02 -0800
committer Jeff Brown <jeffbrown@google.com> 2011-02-19 05:23:10 -0800
commit3ea4de826d95c580c28d854c677ded0d15d220a8 (patch)
tree1bdaeb75ab7922160f2f22b1e62af0ca1e6b759e /libs/ui/Keyboard.cpp
parentd647fdcb9cfa0ab2438d7e37a32c4d48357c9b64 (diff)
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
Diffstat (limited to 'libs/ui/Keyboard.cpp')
-rw-r--r--libs/ui/Keyboard.cpp24
1 files changed, 21 insertions, 3 deletions
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) {