blob: 2a742f9cf473704d17cc77023f1810b365e6bac3 [file] [log] [blame]
Michael Wright872db4f2014-04-22 15:03:51 -07001/*
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 Yefff9edb2020-08-13 16:12:54 -070022#include <unordered_map>
Michael Wright872db4f2014-04-22 15:03:51 -070023
Michael Wright872db4f2014-04-22 15:03:51 -070024namespace android {
25
26template<typename T, size_t N>
27size_t size(T (&)[N]) { return N; }
28
29struct InputEventLabel {
30 const char *literal;
31 int value;
32};
33
Chris Ye4958d062020-08-20 13:21:10 -070034// 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 Wright872db4f2014-04-22 15:03:51 -070036
Chris Ye4958d062020-08-20 13:21:10 -070037class InputEventLookup {
38public:
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
56private:
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 Wright872db4f2014-04-22 15:03:51 -070068};
69
Michael Wright872db4f2014-04-22 15:03:51 -070070} // namespace android
71#endif // _LIBINPUT_INPUT_EVENT_LABELS_H