| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2008 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | #ifndef _LIBINPUT_INPUT_EVENT_LABELS_H | 
 | 18 | #define _LIBINPUT_INPUT_EVENT_LABELS_H | 
 | 19 |  | 
 | 20 | #include <input/Input.h> | 
 | 21 | #include <android/keycodes.h> | 
| Chris Ye | fff9edb | 2020-08-13 16:12:54 -0700 | [diff] [blame] | 22 | #include <unordered_map> | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 23 |  | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 24 | namespace android { | 
 | 25 |  | 
 | 26 | template<typename T, size_t N> | 
 | 27 | size_t size(T (&)[N]) { return N; } | 
 | 28 |  | 
 | 29 | struct InputEventLabel { | 
 | 30 |     const char *literal; | 
 | 31 |     int value; | 
 | 32 | }; | 
 | 33 |  | 
| Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 34 | //   NOTE: If you want a new key code, axis code, led code or flag code in keylayout file, | 
 | 35 | //   then you must add it to InputEventLabels.cpp. | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 36 |  | 
| Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 37 | class InputEventLookup { | 
 | 38 | public: | 
 | 39 |     static int lookupValueByLabel(const std::unordered_map<std::string, int>& map, | 
 | 40 |                                   const char* literal); | 
 | 41 |  | 
 | 42 |     static const char* lookupLabelByValue(const std::vector<InputEventLabel>& vec, int value); | 
 | 43 |  | 
 | 44 |     static int32_t getKeyCodeByLabel(const char* label); | 
 | 45 |  | 
 | 46 |     static const char* getLabelByKeyCode(int32_t keyCode); | 
 | 47 |  | 
 | 48 |     static uint32_t getKeyFlagByLabel(const char* label); | 
 | 49 |  | 
 | 50 |     static int32_t getAxisByLabel(const char* label); | 
 | 51 |  | 
 | 52 |     static const char* getAxisLabel(int32_t axisId); | 
 | 53 |  | 
 | 54 |     static int32_t getLedByLabel(const char* label); | 
 | 55 |  | 
 | 56 | private: | 
 | 57 |     static const std::unordered_map<std::string, int> KEYCODES; | 
 | 58 |  | 
 | 59 |     static const std::vector<InputEventLabel> KEY_NAMES; | 
 | 60 |  | 
 | 61 |     static const std::unordered_map<std::string, int> AXES; | 
 | 62 |  | 
 | 63 |     static const std::vector<InputEventLabel> AXES_NAMES; | 
 | 64 |  | 
 | 65 |     static const std::unordered_map<std::string, int> LEDS; | 
 | 66 |  | 
 | 67 |     static const std::unordered_map<std::string, int> FLAGS; | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 68 | }; | 
 | 69 |  | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 70 | } // namespace android | 
 | 71 | #endif // _LIBINPUT_INPUT_EVENT_LABELS_H |