blob: 904c8f305fc75bba42d49514927111eb76ecef73 [file] [log] [blame]
Jeff Browna3477c82010-11-10 16:03:06 -08001/*
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 _UI_KEY_LAYOUT_MAP_H
18#define _UI_KEY_LAYOUT_MAP_H
19
20#include <stdint.h>
21#include <utils/Errors.h>
22#include <utils/KeyedVector.h>
23#include <utils/Tokenizer.h>
24
25namespace android {
26
27/**
Jeff Brown3ea4de82011-02-19 01:08:02 -080028 * Describes a mapping from keyboard scan codes and joystick axes to Android key codes and axes.
Jeff Browna3477c82010-11-10 16:03:06 -080029 */
30class KeyLayoutMap {
31public:
32 ~KeyLayoutMap();
33
34 static status_t load(const String8& filename, KeyLayoutMap** outMap);
35
Jeff Brown3ea4de82011-02-19 01:08:02 -080036 status_t mapKey(int32_t scanCode, int32_t* keyCode, uint32_t* flags) const;
37 status_t findScanCodesForKey(int32_t keyCode, Vector<int32_t>* outScanCodes) const;
38
39 status_t mapAxis(int32_t scanCode, int32_t* axis) const;
Jeff Browna3477c82010-11-10 16:03:06 -080040
41private:
42 struct Key {
43 int32_t keyCode;
44 uint32_t flags;
45 };
46
Jeff Brown3ea4de82011-02-19 01:08:02 -080047 KeyedVector<int32_t, Key> mKeys;
48 KeyedVector<int32_t, int32_t> mAxes;
Jeff Browna3477c82010-11-10 16:03:06 -080049
50 KeyLayoutMap();
51
52 class Parser {
53 KeyLayoutMap* mMap;
54 Tokenizer* mTokenizer;
55
56 public:
57 Parser(KeyLayoutMap* map, Tokenizer* tokenizer);
58 ~Parser();
59 status_t parse();
60
61 private:
62 status_t parseKey();
Jeff Brown3ea4de82011-02-19 01:08:02 -080063 status_t parseAxis();
Jeff Browna3477c82010-11-10 16:03:06 -080064 };
65};
66
67} // namespace android
68
69#endif // _UI_KEY_LAYOUT_MAP_H